first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

VBScript and ASP PROBLEM: Dates with the Form mm/dd/yyyy Cannot Be Passed in Query String

If your design demands passing dates in an HTTP Query String, you will quickly find that this is a badly formed URI:

http://localhost/MyPage.html?vDate=#01/02/1999#

where the "#" characters imply that this is a date to be submitted to an .MDB file. You might be able to get by with this:

http://localhost/MyPage.html?vDate=X01-02-1999X

where "X" is some dummy replacement character. But I find this unattractive. Instead of coming up with my own unattractive replacement characters, the ASP Server object has its URLEncode method, where:

"http://localhost/MyPage.html?" _
    & "vDate=" & Server.URLEncode("#01/02/1999#")

yields

http://localhost/MyPage.html?vDate=%2301%2F02%2F1999%23

Strangely, I would rather convert the date to its underlying numerical format. The following returns the number 36162:

CDbl(DateSerial(1999,01,02))

which may lead to the question, How can I easily parse the year, month and day out of a "date string"? The answer is to use the Year, Month and Day functions respectively:

CDbl(DateSerial(Year("01/02/1999"), _
    Month("01/02/1999"), _
    Day("01/02/1999")))

After conversion, the URI now looks like the following:

http://localhost/MyPage.html?vDate=36162

Of course, to convert a serial date double back to its locale value requires the CDate() function:

CDate(36162) = 01/02/1999

Additionally, we should recall the TimeSerial() function and CDate(), its use on TimeSerial() values as well. For more information, as of this writing, Microsoft's KB has the article "HOWTO: Get Date or Serial Result from DateSerial or DateValue" (Q95510) at:

http://support.microsoft.com/support
    /kb/articles/Q95/5/10.ASP
mod date: 2002-01-08T02:20:39.000Z