Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a day number in a year 4

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am trying to make a day planner for a year. Is there such a thing as a daynumber of the year. If so, if I have 12/03/2003 how do I get the DayNumber. If there is no such thing, any ideas how it could be got. Many thanks.
 
ZOR,

I cant find a Julian Function. but how bout this...
Code:
Function DayOfYear(dte As Date) As Integer
    DayOfYear = dte - DateSerial(Year(dte), 1, 1)
End Function
:)


Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Think I need to add 1 to the return value...
Code:
Function DayOfYear(dte As Date) As Integer
    DayOfYear = dte - DateSerial(Year(dte), 1, 1) + 1
End Function
[blush] sorry!

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Or the format alternative
Code:
Function DayOfYear(dte As Date) As Integer
    DayOfYear = Val ( Format ( dte, "y" ) )
End Function
 
You both did well guys. Star for you both. Do you happen to know how to get a year date back from a day number. I would presume it would have to be given the year to work with. Many thanks again
 
You could do something like:
DateAdd("d", DayOfYear, "1/1/" & strYear)
 
actually you'll have to subtract a day from DayOfYear because DayOfYear = 1 represents Jan. 1 and you would want to add 1 day to it.

DateAdd("d", DayOfYear -1, "1/1/" & strYear)
 
Many thanks, getting my date back works splendid. You too have a star, and thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top