Displaying time from Datetime datatype

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sreenivas

    Displaying time from Datetime datatype

    Hi every one,
    I am new to sql server2005,I have datetime column
    in my database ..I need to display only time part of the datetime .I
    need to display in AM/PM format ..datetime is stored in this format mm/
    dd/yyyy hh:mm:ss AM/PM .I need to display in this format hh:mm:ss AM/
    PM ,How can i do that?? I searched for this on net but i got 24hour
    format .
    i tried this on my own ,but no hope!

    Thanks in advance,
  • Plamen Ratchev

    #2
    Re: Displaying time from Datetime datatype

    The DATETIME data type does not have format but it is rather stored as
    binary value. Formatting is normally best done on the client side.

    In T-SQL you can use the CONVERT function with style 109 and a bunch of
    string manipulations to get the time formatted as string:

    SELECT RIGHT('0' +
    LTRIM(STUFF(RIG HT(
    CONVERT(CHAR(26 ), CURRENT_TIMESTA MP, 109)
    , 14),
    9, 4, ' ')),
    11);

    --
    Plamen Ratchev

    Comment

    • Sreenivas

      #3
      Re: Displaying time from Datetime datatype

      On Oct 31, 10:39 am, Plamen Ratchev <Pla...@SQLStud io.comwrote:
      The DATETIME data type does not have format but it is rather stored as
      binary value. Formatting is normally best done on the client side.
      >
      In T-SQL you can use the CONVERT function with style 109 and a bunch of
      string manipulations to get the time formatted as string:
      >
      SELECT RIGHT('0' +
              LTRIM(STUFF(RIG HT(
              CONVERT(CHAR(26 ), CURRENT_TIMESTA MP, 109)
                            , 14),
                          9, 4, ' ')),
                    11);
      >
      --
      Plamen Ratchevhttp://www.SQLStudio.c om
      Plamen Ratchev..
      Thanks a lot for your help

      Comment

      Working...