Thread: Compare 2 dates
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Compare 2 dates

On Thu, 21 Oct 2004 09:23:45 -0700, "Terri"
wrote:

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