Formatting Dates in SQL 2005

  • DECLARE @Date DATETIME

    SET @Date = '2009-05-01 13:43:15'

    SELECT REPLACE(CONVERT(varchar(13),@Date,10),'-','')

    Check out the CONVERT function in BOL

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • Thanks, that worked. I modified it a bit for a column I need to format.

    replace(convert(varchar(13),end_date,10),'-','')

  • Glad I could help 🙂

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life

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

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