date comparison

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shankari07
    New Member
    • Sep 2007
    • 16

    date comparison

    hi guys,
    i have two dates in the format dd-mmm-yyyy i have to compare whether the first date is greater than than the second date
    eg. date1 = 01-jul-2007 date2 = 28-jun-2007 compare date1 and date2
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by shankari07
    hi guys,
    i have two dates in the format dd-mmm-yyyy i have to compare whether the first date is greater than than the second date
    eg. date1 = 01-jul-2007 date2 = 28-jun-2007 compare date1 and date2
    [CODE=vb]Dim Date1 As Date, Date2 As Date

    'VBA will convert Date Formats of dd-mmm-yyyy to mm/dd/yyyy
    Date1 = #7/1/2007#
    Date2 = #6/28/2007#

    If Date1 > Date2 Then
    MsgBox "Date 1 > Date 2"
    Else
    MsgBox "Date 1 <= Date 2"
    End If

    OR

    If DateDiff("d", Date1, Date2) < 0 Then
    MsgBox "Date 1 > Date 2"
    Else
    MsgBox "Date 1 <= Date 2"
    End If[/CODE]

    Comment

    Working...