Results 1 to 11 of 11

Thread: Actual date of the year

  1. #1

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249

    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

  2. #2
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843
    I've not heard of this function, can you post an example
    of VB code that uses this? I could use this.
    Merry Christmas

  3. #3

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    I have never used it myself. I found it by looking through my MSDN help.
    Normal is boring...

    smh

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Couldn't you write a code snippet yourself?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    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

  6. #6
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    VB Code:
    1. print dateserial(year(date),month(date),X)
    Last edited by dis1411; Feb 8th, 2002 at 01:19 PM.

  7. #7

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    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

  8. #8
    RobIII
    Guest
    Simple:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Debug.Print GetDate(0)   'January 1st   = Day zero
    5.     Debug.Print GetDate(1)   'January 2nd   = Day 1
    6.     Debug.Print GetDate(135) 'May 16th      = Day 135
    7.     Debug.Print GetDate(364) 'December 31st = Day 364
    8. End Sub
    9.  
    10.  
    11. Private Function GetDate(intDayNumber As Integer) As Date
    12.     GetDate = DateAdd("d", intDayNumber, "1/1/" & Year(Now))
    13. End Function

  9. #9
    RobIII
    Guest
    Or for "normal" counting of days:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Debug.Print GetDate(1)   'January 1st   = Day 1
    5.     Debug.Print GetDate(2)   'January 2nd   = Day 2
    6.     Debug.Print GetDate(136) 'May 16th      = Day 136
    7.     Debug.Print GetDate(365) 'December 31st = Day 365
    8. End Sub
    9.  
    10.  
    11. Private Function GetDate(intDayNumber As Integer) As Date
    12.     GetDate = DateAdd("d", intDayNumber - 1, "1/1/" & Year(Now))
    13. End Function

    Really ain't that hard

  10. #10
    RobIII
    Guest
    Or, for any given year:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Debug.Print GetDate(1, 2005)   'January 1st   = Day 1, 2005
    5.     Debug.Print GetDate(2, 1999)   'January 2nd   = Day 2, 1999
    6.     Debug.Print GetDate(136)       'May 16th      = Day 136, Current year
    7.     Debug.Print GetDate(365, 2090) 'December 31st = Day 365, 2090
    8. End Sub
    9.  
    10.  
    11. Private Function GetDate(intDayNumber As Integer, Optional intYear As Integer = -1) As Date
    12.     If intYear = -1 Then intYear = Year(Now)
    13.     GetDate = DateAdd("d", intDayNumber - 1, "1/1/" & intYear)
    14. End Function

    Now, anything else?

  11. #11

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    Thanks for the help!
    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
  •  



Click Here to Expand Forum to Full Width