Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Compare 2 dates

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!"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Compare 2 dates

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"


In article ,
"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!"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Compare 2 dates

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

--
Regards,
Tom Ogilvy


"Terri" wrote in message
...
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!"



  #4   Report Post  
Posted to microsoft.public.excel.programming
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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Compare 2 dates

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

"Tom Ogilvy" wrote:

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

--
Regards,
Tom Ogilvy


"Terri" wrote in message
...
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!"




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare two dates Dave Excel Discussion (Misc queries) 3 November 18th 09 12:41 PM
compare 2 tables of dates to find the preceding dates Babi Excel Worksheet Functions 3 October 28th 08 05:52 AM
Compare dates with lag adimar Excel Worksheet Functions 5 February 2nd 08 11:21 AM
compare dates Thea Excel Worksheet Functions 1 April 27th 07 01:17 AM
how do I compare two dates? SlipperyPete Excel Worksheet Functions 3 April 19th 06 05:40 PM


All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"