By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,449 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,449 IT Pros & Developers. It's quick & easy.

Converting a Date to Time Only

benchpolo
100+
P: 142
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.
Nov 7 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,430
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.
Nov 7 '12 #2

ck9663
Expert 2.5K+
P: 2,878
Try using style 14 or 114. I think that will only return the time in 24H format.

Happy Coding!!!

~~ CK
Nov 7 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.