Format current system date in asp so you can query sql datetime field

If you have a sql datetime field that looks like this: "2013-02-14 00:00:00.000", it is hard to query from an asp page unless you get your date formatted in your asp page to be formatted the same as your sql datetime field. There are probably lots of ways to do that.

Here's one approach:

Step 1 - format the current system date in asp to generate a date that looks like: 02/15/2013

Dim today

today = cstr(formatdatetime(now(),2))

If len(today)=9 then

today ="0" + today

End if

Step 2 - format your date in your sql query to also look like: 02/15/2013


Step 3 - ending sql query

"Select * from table where convert(char(10),datefieldinsql,101)='" & today & "'"

Notice that we put a single quote around the today variable.