Formatting Dates in SQL 2005

  • I am stuck trying to format a date field to output as MMDDYY. I can get it to come out as any of the following formats but need to have MMDDYY.

    yyyy/mm/dd

    yyyymmdd

    mm-dd-yyyy

    So basically I need to format the following data 2009-05-01 13:43:15 as 050109.

    Any help would be appreciated.

  • 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 4 posts - 1 through 3 (of 3 total)

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