Problem with a date statement

# Thread: Problem with a date statement

1. Senior Member
Join Date
Dec 1969
Posts
1,030

## Problem with a date statement

if theDate &#062;= "6/2/2003" AND theDate &#060;= "6/7/2003" OR theDate &#062;= "6/24/2003" AND theDate &#060;= "6/28/2003" then<BR><BR>I get 6-2 through 6-7 just fine. But after that I get 6-20 through 6-30 despite the fact that the statement reads 6-24 through 6-28. What am I missing here???

2. Member
Join Date
Dec 1969
Posts
31

## RE: Problem with a date statement

enclose them in parenthesis<BR>

3. Senior Member
Join Date
Dec 1969
Posts
1,030

## Huh? They are. ??? <eop>

.

4. Senior Member
Join Date
Dec 1969
Posts
3,195

## RE: Huh? They are. ??? <eop>

if (theDate &#062;= "6/2/2003" AND theDate &#060;= "6/7/2003") OR <BR> (theDate &#062;= "6/24/2003" AND theDate &#060;= "6/28/2003") then <BR><BR>What&#039;s the problem?! ; )<BR>

5. Senior Member
Join Date
Dec 1969
Posts
1,030

## Duh on me! Thanks <eop>

.

6. Senior Member
Join Date
Dec 1969
Posts
1,030

## ODDLY ENOUGH

Same dang problem! 6-2 to 6-7 just fine. Then I get 6-20 to 6-30????

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## What DATES? There are NONE...

...in any of that code you are showing.<BR><BR>All you have are *STRINGS*.<BR><BR>And, yes, "2" is always greater than "19991881872119992288111" when you are comparing *STRINGS*.<BR><BR>Just *exactly* the same way that "B" is always greater than "ABRACDABRA KALAMAZOO".<BR><BR>Strings are compared *character* by character. <BR><BR>If you want to compare *dates*, then USE dates.<BR><BR>&#060;%<BR>theDate = CDate(theDate) &#039; to ensure it *is* a date<BR><BR>if (theDate &#062;= CDate("6/2/2003") AND theDate &#060;= CDate("6/7/2003")) OR <BR> (theDate &#062;= CDate("6/24/2003") AND theDate &#060;= CDate("6/28/2003")) then <BR> ...<BR>%&#062;<BR><BR>It would be even better (faster, and works no matter where in the world the code is run) if you used DateSerial:<BR><BR>&#060;%<BR>theDate = CDate(theDate) &#039; to ensure it *is* a date<BR><BR>if ( theDate &#062;= DateSerial(2002,6,2) AND theDate &#060;= DateSerial(2003,6,7) ) OR <BR> (theDate &#062;= DateSerial(2003,6,24) AND theDate &#060;= DateSerial(2003,6,28) ) then <BR> ...<BR>%&#062;<BR><BR>[CDate("6/2/2003") can be taken as June 2, 2003 *OR* taken as 6 February 2003, depending on the LCID of the computer you are running on. DateSerial *always* uses the order year, month, day.]<BR>

8. Senior Member
Join Date
Dec 1969
Posts
1,030

## As usual

An answer and a lesson. Thanks I feel a little stupid here because I should have known that. Won&#039;t forget again!

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Hey, you weren't alone!

Pete got hooked in, too.<BR><BR>I would guess that you use SQL Server? Where you *can* compare dates and strings, becuz TSQL automatically converts strings to dates for you. Get into that habit, and it&#039;s easy to forget that most other languages (all other? I can&#039;t think of an exception) don&#039;t do that.<BR><BR>

10. Senior Member
Join Date
Dec 1969
Posts
1,030

## I wish I could

Nope, using Access. The reason I said I should have known that is when I wrote that page 6 mos ago at the top I wrote:<BR><BR>If request("newdate") &#062; "" then<BR>newdate = request("newdate")<BR>theDate = cdate(newdate)<BR>else<BR>thedate = Cdate(Date)<BR><BR>I had trouble then for the same exact reason. You would **THINK** I would have learned from that fiasco! But nope. Added the code above and created another one. Think I&#039;ll tatoo Cdate on my forehead! <BR>end if<BR>fwddate = Cdate(theDate +1)<BR>backdate = Cdate(theDate -1)<BR>wday = weekdayname(weekday(theDate))

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•