comparing dates

1. Member
Join Date
Dec 1969
Posts
41

comparing dates

Hi,<BR><BR>I am trying to set an expiration date for some content. I was originally using the following:<BR><BR>&#060;% if Date &#060;= "4/21/2003" then %&#062;<BR>content here<BR>&#060;% end if %&#062;<BR><BR>This, however, presents the problem of the content not be displayed on April 3 (or 4th, 5th, etc), because IIS sees the day &#039;3&#039; to be greater than &#039;21&#039;.<BR><BR>I have a book on ASP that list numerous date functions, but none of them seem to be of any use in this particular situation. Anyone have any ideas? Thanks-<BR><BR>Chris Giesler

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

Nope, you're comparing STRINGS

As you correctly analyzed, so 3 points for you. You&#039;d be amazed how many people don&#039;t figure that out.<BR><BR>If you want to compare dates, be sure they *are* dates:<BR><BR>&#060;%<BR>If Date() &#060;= CDate("4/21/2003") Then <BR>%&#062;<BR><BR>The Date() function will always return a date.<BR><BR>The CDATE function will convert a string (or a number, but not the way you would expecte) into a date.<BR><BR>You can also use DateSerial, which I prefer:<BR><BR>&#060;%<BR>If Date() &#060;= DateSerial(2003,4,21) Then <BR>%&#062;<BR><BR>Hokay?<BR><BR>

3. Member
Join Date
Dec 1969
Posts
41

RE: Nope, you're comparing STRINGS

Hokay, Bill. Thanks for your lightning fast response.

4. Senior Member
Join Date
Dec 1969
Posts
167

RE: Nope, you're comparing STRINGS

Just out of curiousity, would putting the # signs work? I ask only because of my own question regarding the INSERT SQL statements...<BR><BR>Defiant005

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

Yes...

...because #3/15/2003# (or whatever) *IS* a Date value. A literal date value in VB, VBScript, and VBA (which means it works in Access and Excel and the rest of MS Office).<BR><BR>

Posting Permissions

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