|
-
Feb 8th, 2002, 12:15 PM
#1
Thread Starter
Addicted Member
Actual date of the year
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
Normal is boring...
 smh 
-
Feb 8th, 2002, 12:27 PM
#2
Fanatic Member
I've not heard of this function, can you post an example
of VB code that uses this? I could use this.
-
Feb 8th, 2002, 12:32 PM
#3
Thread Starter
Addicted Member
I have never used it myself. I found it by looking through my MSDN help.
Normal is boring...
 smh 
-
Feb 8th, 2002, 12:54 PM
#4
Well ...
Couldn't you write a code snippet yourself?
.
-
Feb 8th, 2002, 01:03 PM
#5
Thread Starter
Addicted Member
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
Normal is boring...
 smh 
-
Feb 8th, 2002, 01:07 PM
#6
Frenzied Member
VB Code:
print dateserial(year(date),month(date),X)
Last edited by dis1411; Feb 8th, 2002 at 01:19 PM.
-
Feb 8th, 2002, 02:02 PM
#7
Thread Starter
Addicted Member
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.
Normal is boring...
 smh 
-
Feb 8th, 2002, 03:07 PM
#8
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
-
Feb 8th, 2002, 03:09 PM
#9
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
-
Feb 8th, 2002, 03:14 PM
#10
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?
-
Feb 8th, 2002, 03:26 PM
#11
Thread Starter
Addicted Member
Normal is boring...
 smh 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|