What is the best way to encode a DATETIME value given three integer values:
Year, Month, Day (I only need precision up to a given day, no time values).
I know i can form a date string, but I am relunctant to use that since it is dependant on the Language settings of the current session.
for example:
SELECT CAST(CAST(2004 AS VARCHAR) + '/' + CAST(1 AS VARCHAR) + '/' + CAST(5 AS VARCHAR) AS DATETIME);
Is January 5, 2004 when the session's language is set toENGLISH/US_ENGLISH, but equals May 1, 2004 when the session's language is set to FRENCH;
Basically I'm looking for something like MakeDate(Year AS INT, Month AS TINYINT, Day AS TINYINT) that returns a DATETIME value.The string '2004-01-05' is always January 5, 2004 and the string '2004-05-01' is always May 1, 2004. The ISO standard date string format is a wonderful thing!
-PatP|||thanks Pat1...I had noticed the ASCII (YYYYMMDD) format always worked...but I didn't like the idea of manually padding the Months/days with a '0' for Months/days in the 1-9 range.....but the '-' gives me the proper separator for years/months/days....to think that any select statement that returns a date does so in the format you mentionned, and I didn't notice....I need some sleep.
thanks again.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment