Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    84

    Unanswered: DATETIME question

    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.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  3. #3
    Join Date
    Oct 2003
    Posts
    84
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •