[thelist] SQL Dates

Martyn Haigh McFly at Phiniusgage.com
Fri Jan 3 04:51:01 CST 2003

Just spent countless hours confused by this one, so I thought I'd share

<tip type="Formatting SQL Dates in ASP" author="Martyn Haigh">
SQL is really picky about what format you use when using dates, and this
can often cause many hours of pulling your hair out. I speak from

The normal Date() or  Now() functions will often throw up unexpected
errors, so instead why not use this handy routine I copied from
4GuysFromRolla.com and put a stop to all your SQL Date headaches.

Funciton formatSQLDate(dateToFormat)
	Dim aDay
	Dim aMonth
	Dim aYear

	aDay = Day(dateToFormat)
	aMonth = Monthname(Month(dateToFormat),True)
	aYear = Year(dateToFormat)

	formatSQLDate= aDay & "-" & aMonth & "-" & aYear
End function

This will give you a date in this format : 2-Jan-2003
Which is SQL friendly.
(don't forget to use those delimiters [#'s] when working with dates!)


More information about the thelist mailing list