WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Mod (Modulo) Function

Keywords: 	  Mod (Modulo) Function

Question:

I copied the following code from the website but am confused by the "mod7". Can anyone tell me what this does and do you have to "unmod" an integer to make it behave like an integer in other mathematical functions. I am trying to find the date of the next Sunday after the current date, sounds easy eh !? Anyone have code for that ?
a=TimeYmdHms( )
b=TimeJulianDay(a)c=((b+5) mod 7) + 1
day=ItemExtract(c, "Sun Mon Tue Wed Thu Fri Sat", " ")
realdate = TimeJulToYmd(b)
line=StrCat("Julian Date-> ", b,@CRLF,"Day of week-> ",day,@CRLF,"Real date-> ",realdate) 

Answer:

mod is the "modulo" function. Also sometimes known as the "remainder" function.

Basically it means "divide by 7 and keep the remainder"

It is used to figure conver the julian date to a number between 0 and 6 that can be used to figure out the day of the week.

About the same as (baring typos)

bignum=123456
temp=bignum / 7
mod7 = bignum - (temp * 7)
or just
mod7 = bignum mod 7



a=TimeYmdHms( )
b=TimeJulianDay(a)
c=((b+5) mod 7)

;Message("day of week 0 - 6",c)

days2sunday=7 - c

;Maybe if today is sunday, did you want *next* sunday?
; if days2sunday==0 then days2sunday=days2sunday+7

juliansunday=b+days2sunday

sunday=TimeJulToYmd(juliansunday)
Message("Sunday",sunday)





Article ID:   W15503
File Created: 2003:05:28:10:20:48
Last Updated: 2003:05:28:10:20:48