Converting a Date to Time Only

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • benchpolo
    New Member
    • Sep 2007
    • 142

    Converting a Date to Time Only

    Scenario: I have 1 field REQDATE. 2 input box 1 date field and 1 time field. I have no issue pulling the date field, but I need to convert REQDATE to a time data. Format should be 12 HR format not 24 HR format. I have the TSQL below, but it is not giving the correct result I want.

    Expected Result: 11:30 AM or 1:30 PM
    TSQL: SELECT convert(time, GETDATE(), 101 ) as x

    Please advice.
    Thanks.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You misunderstand what the style parameter is for. What you need to do is convert it to a char in the style that you need, in this case use 100, and then substring out the pieces that you want.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Try using style 14 or 114. I think that will only return the time in 24H format.

      Happy Coding!!!

      ~~ CK

      Comment

      Working...