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
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
The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved
When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day
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
You could also use the datediff() function and check the return value
Or you can force-change your dates to long or double and then compare them like any numericals
For health reasons i try to avoid reading unformatted Code
Or you could try:
Datediff:Code:If Format("14/11/2012", "dd-mm-yy") > Format(Now, "dd-mm-yy") Then Debug.Print "Bigger" Else Debug.Print "Smaller" End If
Code:If DateDiff("d", Now, "14/11/2012") > 0 Then Debug.Print "Bigger" Else Debug.Print "Smaller" End If
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