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

Time - Timer and Date Functions
plus

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

Get day of Year Julian date

 Keywords:  3 digit Day of Year Julian date

Question:

Where I work we use a calendar that starts with Julian Date 001 on January 1 and ends with Julian Date 365 on December 31.

I would like to make a little script that would get return the Julian Date based on the date.

Any suggestions?

Answer:

Julian date has a *whole* bunch of different definitions. We call the one you want "Day of year". Try...

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)

Also here are some UDfs you can use to determine this type of information

#DefineFunction DayOfYear(ToDate)
    ThisYear=ItemExtract(1,ToDate,":")
    JanFirst="%thisyear%:01:01:00:00:00"
    JanFirstJulian=TimeJulianDay(JanFirst)
    ToJulian=TimeJulianDay(ToDate) 
    doy=ToJulian-JanFirstJulian+1
    return (doy)
#EndFunction

#DefineFunction DayOfWeek(ToDate)
    ToJulian=TimeJulianDay(ToDate) 
    dayofweekcode=(ToJulian+5) mod 7
    day=ItemExtract(dayofweekcode+1, "Sun Mon Tue Wed Thu Fri Sat", " ")
    return(day)
#endfunction

now=TimeYmdHms()
doy=DayOfYear(now)
dow=DayOfWeek(now)
Message(doy,dow)
exit

Article ID:   W14978
File Created: 2001:11:08:12:41:16
Last Updated: 2001:11:08:12:41:16