Date format for mm/dd/yyyy h:mm:ss AM/PM ?

  • Hi

    Having a problem trying to figure out formatting a datettime as "mm/dd/yyyy h:mm:ss AM/PM"

    Any help would be great!!

    Thanks

  • There's no direct code, but this should help.

    DECLARE @Datetime datetime = GETDATE();

    SELECT @Datetime, CONVERT(char(10), @Datetime,101) + STUFF( SUBSTRING( CONVERT(char(100), @Datetime,109), 12, 15), 10, 4, ' ');

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • jbalbo (12/7/2016)


    Hi

    Having a problem trying to figure out formatting a datettime as "mm/dd/yyyy h:mm:ss AM/PM"

    Any help would be great!!

    Thanks

    datetime fields do not have a format, because they need to be language and locale neutral. A format is applied by the client application. You'll either need to set the datetime format in your client application or convert your datetime field to a string.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Thanks !!!!

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

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