I know the DayofYear function returns the number of the day in the year. Is there any way to reverse that?
Ex: Enter 32 and you should get 2/1/02 returned.
Thanks,
SMH
Printable View
I know the DayofYear function returns the number of the day in the year. Is there any way to reverse that?
Ex: Enter 32 and you should get 2/1/02 returned.
Thanks,
SMH
I've not heard of this function, can you post an example
of VB code that uses this? I could use this.
I have never used it myself. I found it by looking through my MSDN help.
Couldn't you write a code snippet yourself?
.
I did write a quick function, but it will only do this year (2002).
Ex: The following code is looking for day #32 which is Feb 1.
Dim M
Dim D
Dim Y
Dim newDate As Date
M = DateTime.Month(32)
D = DateTime.Day(32)
Y = DateTime.Year(Now)
newDate = M & "/" & D & "/" & Y
'Must increment by one day, as the 1st day of the year = 0
newDate = newDate + 1
VB Code:
print dateserial(year(date),month(date),X)
I don't understand how that would work.
I am given day #225 of 2001. I have no idea what month or day of the month it is. I just know that it is the 225th day of 2001.
Simple:
VB Code:
Option Explicit Private Sub Form_Load() Debug.Print GetDate(0) 'January 1st = Day zero Debug.Print GetDate(1) 'January 2nd = Day 1 Debug.Print GetDate(135) 'May 16th = Day 135 Debug.Print GetDate(364) 'December 31st = Day 364 End Sub Private Function GetDate(intDayNumber As Integer) As Date GetDate = DateAdd("d", intDayNumber, "1/1/" & Year(Now)) End Function
Or for "normal" counting of days:
VB Code:
Option Explicit Private Sub Form_Load() Debug.Print GetDate(1) 'January 1st = Day 1 Debug.Print GetDate(2) 'January 2nd = Day 2 Debug.Print GetDate(136) 'May 16th = Day 136 Debug.Print GetDate(365) 'December 31st = Day 365 End Sub Private Function GetDate(intDayNumber As Integer) As Date GetDate = DateAdd("d", intDayNumber - 1, "1/1/" & Year(Now)) End Function
Really ain't that hard :)
Or, for any given year:
VB Code:
Option Explicit Private Sub Form_Load() Debug.Print GetDate(1, 2005) 'January 1st = Day 1, 2005 Debug.Print GetDate(2, 1999) 'January 2nd = Day 2, 1999 Debug.Print GetDate(136) 'May 16th = Day 136, Current year Debug.Print GetDate(365, 2090) 'December 31st = Day 365, 2090 End Sub Private Function GetDate(intDayNumber As Integer, Optional intYear As Integer = -1) As Date If intYear = -1 Then intYear = Year(Now) GetDate = DateAdd("d", intDayNumber - 1, "1/1/" & intYear) End Function
Now, anything else? :) :) :)
Thanks for the help!