[thelist] Date and Time issue Worldwide

Paul Cowan paul at wishlist.com.au
Mon Apr 15 19:25:18 CDT 2002


Hey all,

After all the date-related discussion, you can never go wrong with this:

<tip type="International Date Handling" author="Paul Cowan">
Frustrated by illogical date formats? Simple. Always pass your dates to a
database or other system with the format:
	yyyy-mm-dd
For example, Christmas 1999 is
	1999-12-25

Why? Because, in all my travels, I have never ever found a
database which won't parse this correctly. It's fairly trivial to
create a function in your choice of language to convert dates to
this format: and if you pass those around whenever you can, you
will save yourself untold amounts of grief when what you thought
was the 7th of January comes out as the 1st of July at the other
end (or vice-versa).

A very simple function in VBScript might be:

function FormatDateForDB(datInput)
	FormatDateForDB = Year(datInput) & "-" & _
		right("0" & Month(datInput), 2) & "-" & _
		right("0" & Day(datInput), 2)
end function

and I'm sure you'd have no problems doing the same in any other server-side
language.
</tip>



More information about the thelist mailing list