locked
datetime format RRS feed

  • Question

  • is there a t sql conver code for datetime to show in the following format

    mm/dd/yyyy hh/mm/ss


    month/day/year hour/minutes/seconds

    thats it no microseconds (just month,day,year hour,minute,seconds)


    thanks

    justin

    Tuesday, February 15, 2011 6:07 PM

Answers

  • declare @dt datetime

    set @dt = getdate()


    select convert(varchar, @dt, 101) + ' '  + replace(convert(varchar, @dt, 108), ':', '/')
    Thanks, Cool Mind -- If you find my answer helpful, please mark it as Answer.
    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:15 PM
  • You can try this:

    select convert(char(10),getdate(),101)+' '+replace(convert(char(8),getdate(),108),':','/') as result

    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:16 PM
  • Not directly.  But you could do something like

    Select Convert(char(11), GetDate(), 101) + Replace(Convert(char(8), GetDate(), 108), ':', '/')
    
    Tom

    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:18 PM

All replies

  • declare @dt datetime

    set @dt = getdate()


    select convert(varchar, @dt, 101) + ' '  + replace(convert(varchar, @dt, 108), ':', '/')
    Thanks, Cool Mind -- If you find my answer helpful, please mark it as Answer.
    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:15 PM
  • You can try this:

    select convert(char(10),getdate(),101)+' '+replace(convert(char(8),getdate(),108),':','/') as result

    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:16 PM
  • Not directly.  But you could do something like

    Select Convert(char(11), GetDate(), 101) + Replace(Convert(char(8), GetDate(), 108), ':', '/')
    
    Tom

    • Proposed as answer by Naomi N Tuesday, February 15, 2011 6:47 PM
    • Marked as answer by justin_rock Tuesday, February 15, 2011 9:26 PM
    Tuesday, February 15, 2011 6:18 PM
  • thanks guys

     

    Tuesday, February 15, 2011 9:26 PM