date comparison

B

Brad

I'm writing a program the needs to compare a user entered date (enterDate) in
one workbook with a date already present in another workbook(rawDate).
rawDate is formated "mm/dd/yyyy hh:mm:ss" the enterDate is formated
"mm/dd/yyyy". Any suggestions?
 
S

Shasur

Hi Brad

Here is a hint

Sub CheckDate()

Dim rawDate As Date
Dim EnteredDate As Date

rawDate = ActiveCell.Value
EnteredDate = "10/14/2008"

If DateDiff("d", rawDate, EnteredDate) = 0 Then
MsgBox "Dates Match"
ElseIf DateDiff("d", rawDate, EnteredDate) > 0 Then
MsgBox "Entered Date is Greater than the Date"
ElseIf DateDiff("d", rawDate, EnteredDate) < 0 Then
MsgBox "Entered Date is Lesser than the Date"
End If
End Sub

Cheers
Shasur
 
B

Brad

Thanks, that worked great

Shasur said:
Hi Brad

Here is a hint

Sub CheckDate()

Dim rawDate As Date
Dim EnteredDate As Date

rawDate = ActiveCell.Value
EnteredDate = "10/14/2008"

If DateDiff("d", rawDate, EnteredDate) = 0 Then
MsgBox "Dates Match"
ElseIf DateDiff("d", rawDate, EnteredDate) > 0 Then
MsgBox "Entered Date is Greater than the Date"
ElseIf DateDiff("d", rawDate, EnteredDate) < 0 Then
MsgBox "Entered Date is Lesser than the Date"
End If
End Sub

Cheers
Shasur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top