How to obtain the Julian date, Day of Year and Day of Week
Keywords: day of week TimeDayofWeek
Question:
In my latest version of WinBatch (ver 96m, DLL 2.3mbn) a request for a julian date returns a 6 character numeric. But running the same routine from older versions (ver 95d, Wil Interpreter 2.2abm) , using 'run WIL file', returns a 5 character numeric. Is this my imagination or is there an explanation for this difference?Answer:
This was a change put in for year 2000 compliance.There are a lot of different definitions of exactly what is a julian date.
Definition: A Julian representation is simply a count of days since some fixed day in the past.
Originally, I think we started counting from Jan 1 1900, but with the change we started from Jan 1 0000, adding about 730000 days to the number.
You can extract the current day of the week using the following script:
;This example grabs the Time/Day of the Week. a=TimeYmdHms() b=TimeJulianDay(a) c=(b+5) mod 7 day=ItemExtract(c+1, "Sun Mon Tue Wed Thu Fri Sat", " ") line=StrCat("Julian Date-> ", b,@CRLF,"Day of week-> ",day) Message(TimeDate(), line)If you want to determine what day of the week a specific date is, you would substitute the exact date for the "a" variable, as in:
;This example grabs the Time/Day of the Week. a="96:04:12:15:24:00" ; where this is the date for which you want the day of week b=TimeJulianDay(a) c=(b+5) mod 7 day=ItemExtract(c+1, "Sun Mon Tue Wed Thu Fri Sat", " ") line=StrCat("Julian Date-> ", b,@CRLF,"Day of week-> ",day) Message(TimeDate(), line)This example show how to get day Julian date, Day of Year and Day of Week:ToDate=TimeYmdHms() ThisYear=ItemExtract(1,ToDate,":") JanFirst="%thisyear%:01:01:00:00:00" JanFirstJulian=TimeJulianDay(JanFirst) ToJulian=TimeJulianDay(ToDate) dayofyear=ToJulian-JanFirstJulian+1 dayofweekcode=(ToJulian+5) mod 7 day=ItemExtract(dayofweekcode+1, "Sun Mon Tue Wed Thu Fri Sat", " ") line=StrCat("Julian Date-> ", ToJulian,@CRLF,"Day of Year->",DayofYear,@CRLF,"Day of week-> ",day) Message(TimeDate(), line)
Article ID: W13876Filename: Obtain the Julian day of year and week.txt