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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Date from Daynumber

Status
Not open for further replies.

aspvbnetnerd

Programmer
May 16, 2006
278
SE
I want to get the date from the daynumber.
Today daynumber is 317 so I want to get 2007-11-13


Does anybody know how I can return date from a daynumber?

George
 
Use the DateAdd function.

Ex:

MsgBox DateAdd("d", 317 - 1, #1/1/2007#)

Notice that you need to subtract 1 day to get it right. Just for sanity sake, suppose you wanted January 1, 2007. The daynumber would be 1, right? Well, if you add 1 day to 1/1/2007, you would get 1/2/2007, which is not what you want. Essentially, to get the right result, you need to subtract 1.

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
or just

x = #1/1/2007# + 317 - 1

or

x= DateSerial(2007,1,317)

To make this more year independent use:

x= DateSerial(Year(Date()),1,317)

In which case the year can be substituted with a variable:

y=Year(SomeDate)
d = SomeDayNo
x= DateSerial(y,1,d)

 
Ok, Thank you very much.

And if I would want to get the current the daynumber. The other way around.

Get daynumber knowing that the date is 2007-11-13 then I would also use DateAdd?
 


?CDate("2007-11-13") - CDate("2007-01-01")+1

Or use DatePart("y","2007-11-13")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top