Compare 2 dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
How can I compare today's date to 2 other dates? Example:

fDate = Left$(Date$, 2) & Mid$(Date$, 4, 2) & Right$(Date$, 4)
If fDate is equal to or greater than(=>) Nov.1,2004 AND equal to or less
than(=<) Nov.26,2004 Then MsgBox "Warning!"
 
One way:

If Date >= DateSerial(2004, 11, 1) And _
Date <= DateSerial(2004, 11, 26) Then MsgBox "Warning"


alternatively

If Date >= #11/1/2004# And Date <= #11/26/2004# Then MsgBox "Warning"
 
What was wrong with the answer to your original post?

Don't use strings.

Dim dt as Date
dt = Date ' todays date as an example.
if Dt > DateSerial(2004,11,1) and Dt < DateSerial(2004,11,26) then

End if
 
Hello,
How can I compare today's date to 2 other dates? Example:

fDate = Left$(Date$, 2) & Mid$(Date$, 4, 2) & Right$(Date$, 4)
If fDate is equal to or greater than(=>) Nov.1,2004 AND equal to or less
than(=<) Nov.26,2004 Then MsgBox "Warning!"

Here's one way. I simplified things a bit because I don't understand why you
constructed fdate the way you did. Also, I entered the two dates a bit
differently. But this seems to be equivalent:

=====================
Sub foo()
Dim fdate As Date, D1 As Date, D2 As Date

D1 = DateSerial(2004, 11, 1)
D2 = DateSerial(2004, 11, 26)

fdate = Date

If fdate >= D1 And fdate <= D2 Then
MsgBox ("Warning")
End If

End Sub
=================


--ron
 
Tom,
Sorry for the re-post. I got an error on the 1st post and didn't realize it
actually posted. Also, I used your code example and it worked perfectly for
me. Many, many thanks!
Terri
 

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

Back
Top