-
Nov 14th, 2012, 05:35 PM
#1
Comparing Dates
How to compare two dates and determine if MyDate is less than VB Date?
MyDate = "11/15/2012"
Vb Date = "11/14/2012"
If MyDate < Date Then
'
' Do Not Allow
'
Else
'
' Allow
'
End if
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Nov 14th, 2012, 06:11 PM
#2
Re: Comparing Dates
Dim myDate As Date, vDate As Date
myDate = "12/15/2012"
vDate = "11/16/2012"
If myDate < vDate Then
MsgBox "Do Not Allow"
Else
MsgBox "Allow"
End If
OR
Dim myDate As Date
myDate = "11/15/2012"
If myDate < date Then
MsgBox "Do Not Allow"
Else
MsgBox "Allow"
End If
-
Nov 14th, 2012, 07:55 PM
#3
Re: Comparing Dates
You could also use the datediff() function and check the return value
-
Nov 15th, 2012, 12:56 AM
#4
Re: Comparing Dates
Or you can force-change your dates to long or double and then compare them like any numericals
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 15th, 2012, 02:39 AM
#5
New Member
Re: Comparing Dates
Or you could try:
Code:
If Format("14/11/2012", "dd-mm-yy") > Format(Now, "dd-mm-yy") Then
Debug.Print "Bigger"
Else
Debug.Print "Smaller"
End If
Datediff:
Code:
If DateDiff("d", Now, "14/11/2012") > 0 Then
Debug.Print "Bigger"
Else
Debug.Print "Smaller"
End If
-
Nov 15th, 2012, 09:07 AM
#6
Re: Comparing Dates
Note that the code to compare dates using < > must be done using Date variables.
The code shown above using format will not work correctly due to the usage of strings instead of dates.
i.e.
14/12/2012 < 15/11/2012
15/11/2012 < 31/12/2000
12/31/1900 > 1/1/2000
The only way to make it work using strings is to use the yyyy/mm/dd format
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
|