how to extract date from datetime

  • select id,date from temp

    the above statement returns

    1   2004-03-12 17:34:39.923

    2   2004-02-12 17:34:39.923

    i want the out put to be

    1   2004-03-12

    2   2004-02-12

     

    how to do that ?

    Many thanks

     

  • Use convert function

    select id, convert(varchar(10), dd, 120) from temp

  • Just a small typo in this, should be

    select id, convert(varchar(10), date, 120) from temp

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Since the length of the Field created for the Date will always be ten (10) characters, use CONVERT(char(10), ...) rather than CONVERT(varchar(10), ...).  Less overhead, since a Field-length value need not be determined or retained.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply