Forum Moderators: open

Message Too Old, No Replies

converting day of year to a date

         

jefferson

5:33 pm on Dec 16, 2005 (gmt 0)

10+ Year Member



I have an integer that represents the day of year i also have another integer that represents the year. I need to somehow convert both of these numbers into a date using vb.net.

TheNige

3:39 am on Dec 17, 2005 (gmt 0)

10+ Year Member



This should work; there may be other ways..basically creating a new date for January 1st for the selected year then adding the number of days - 1 (since you are starting at day 1 and not 0):

Dim myDay As Integer = 54
Dim myYear As Integer = 2005
Dim baseDate As New Date(myYear, 1, 1)
Dim myDate As Date = baseDate.AddDays(CType(myDay - 1, Double))

john_k

6:28 am on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the DateSerial function.

someDate = DateSerial(lYear, 1, lDay)

Where lYear and lDay are your provided year and day-of-the-year.

jefferson

8:10 pm on Dec 19, 2005 (gmt 0)

10+ Year Member



Thanks guys!