By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,397 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,397 IT Pros & Developers. It's quick & easy.

date comparison

P: 16
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
Sep 12 '07 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,669
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
Expand|Select|Wrap|Line Numbers
  1. Dim Date1 As Date, Date2 As Date
  2.  
  3. 'VBA will convert Date Formats of dd-mmm-yyyy to mm/dd/yyyy
  4. Date1 = #7/1/2007#
  5. Date2 = #6/28/2007#
  6.  
  7. If Date1 > Date2 Then
  8.   MsgBox "Date 1 > Date 2"
  9. Else
  10.   MsgBox "Date 1 <= Date 2"
  11. End If
  12.  
  13.               OR
  14.  
  15. If DateDiff("d", Date1, Date2) < 0 Then
  16.   MsgBox "Date 1 > Date 2"
  17. Else
  18.   MsgBox "Date 1 <= Date 2"
  19. End If
Sep 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.