Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not compare dates

Status
Not open for further replies.

brendasql

Programmer
Apr 1, 2003
58
US
I am trying to do a validation check on dates entered by my users. This date can not be greater than today’s date. The problem is comparing the whole date (MM/DD/YYYY)

Example Values Current date = ‘07/13/2005’
Input Date1 = ‘07/13/2050’
Input Date2 = ‘07/11/2050’

When I compare (InputDate1 to Current Date) I receive my Validation Message, but when I compare (InputDate2 to Current Date) I do not receive any validation error. My code seems to think that InputDate2 is less than the Current Date because the InputDate2(day) is less the Current Date(day).

Here’s my actual code
If FORMATDATE$(rslll(“issue_date”).value) > FORMATDATE$(Now()) then
MSGBOX “The Issue date can not be greater than today’s date.”
ValidationCheck = False
Else
ValidationCheck = True
End If

Has anyone else had this problem? Are there any solutions? I could convert the dates to Julian date, but I hoping that there might be an easier way.
 
Your problem is comparing strings and not dates.

Code:
If IsDate(rslll("issue_date").value) Then
    If CDate(rslll("Issue_date").value > Now Then
        MsgBox "The Issue Date can not be greater than today's date."
        ValidationCheck = False
    Else
        ValidationCheck = True
    End If
End If
 


Hi,

2050? Did you mean 2005?

Skip,

[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue]
 
There was a syntax error in my post, sorry:

Code:
If IsDate(rslll("issue_date").value) Then
    If CDate(rslll("Issue_date").value[b])[/b] > Now Then
        MsgBox "The Issue Date can not be greater than today's date."
        ValidationCheck = False
    Else
        ValidationCheck = True
    End If
End If

Also, I see that your other post in this forum also has to do with data type issues. You may want to read up on data types in the VB Help.
 
Thanks very much bjd4jc! I did have the IsDate function already in my code but I hadn't used the CDate format before. All I had to do was remove my FormatDate and replace with the CDate. Sorry that I reposted a similiar problem with date comparing, I forgot about that thread 2 years ago. Old age is catching me quickly.
 
Ahh, I didn't even look at the date on that post...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top