Results 1 to 3 of 3

Thread: [RESOLVED] Compare Dates While Ignoring Year

  1. #1

    Thread Starter
    Member Suidae's Avatar
    Join Date
    Nov 2001
    Posts
    52

    Resolved [RESOLVED] Compare Dates While Ignoring Year

    This is going to sound wacky but I need to compare two dates while ignoring the year.

    Dim n as Integer
    n = DateDiff(DateInterval.Day, #7/1/2005#, #7/3/2006#)
    n is “367” but what I really need to return is “2”

    I’m trying to get the number of days before or the number of days after an anniversary date. If we were only talking about a single year it would be easy but sometimes these dates span over multiple years. Is there anyway to parse out the year and just compare the month and date? I could use a jumpstart on this one. Thanks!
    I'm a misanthropic philanthropist!
    Frog, the only white meat...

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Compare Dates While Ignoring Year

    VB Code:
    1. Dim d1 As New Date(2005, 7, 1)
    2. Dim d2 As New Date(2006, 7, 3)
    3. Dim tempDate As New Date(d1.Year, d2.Month, d2.Day)
    4. Dim dif As Integer = CInt(DateDiff(DateInterval.Day, d1, tempDate))

    This should do what I think you want.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3

    Thread Starter
    Member Suidae's Avatar
    Join Date
    Nov 2001
    Posts
    52

    Re: Compare Dates While Ignoring Year

    Works Perfectly!
    Thank you!
    I'm a misanthropic philanthropist!
    Frog, the only white meat...

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