Convert getdate() format

  • I want to convert getdate() from say something like this format '2003-07-31 15:16:32.937'(default value) to '7/31/2003 3:16:32 PM'. I tried to convert to varchar with various styles but no style returns the above output. The closest I came was

    select CONVERT(varchar(50) ,getdate(),100) which returned - 'Jul 31 2003 3:16PM'. Help would be greatly appreciated.

  • Maybe a bit convoluted, but it does the trick:

    select CONVERT(varchar ,getdate(),101) + ' ' + LTRIM(STUFF(RIGHT(CONVERT(varchar ,getdate(),109), 14), 9, 4, ''))

    Cheers,

    - Mark


    Cheers,
    - Mark

  • Thank You Mark. That does do the trick.

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

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