Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    2

    Question Unanswered: select only date from datetime field

    I know there must be a way to do this....

    I want to select only the date portion of a datetime field. the date normally shows as similar to '2004-01-01 09:39:52.000'

    I need to return just '2004-01-01'. using convert and cast returns the dates as 'JAN 01 2004' - this won't sort correctly, so it is of no use. any suggestions?

    thanks,
    john

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    select convert(char(10), @YourDate, 120)
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    Code:
     SELECT Convert(CHAR(10), GetDate(), 121)
    if all you need is a character representation. You can also use:
    Code:
    SELECT Convert(DATETIME, Convert(CHAR(10), GetDate(), 121))
    if you need a "real" date to come back.

    -PatP

  4. #4
    Join Date
    Mar 2004
    Posts
    2

    Talking

    Thanks!

Posting Permissions

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