简体   繁体   中英

Best way to change 24hr time to 12hr time?

I currently have a field, IncidentTime, that's displaying time in a 24 hour format. For example, 16:30:00:0000000. How can I convert this field to display the time as "4:30 PM"?

You can convert() . Assuming that your column is of time datatype:

select convert(varchar(8), mycol, 100) formatted_col from mytable

Else, you might need to convert() to a time first:

select convert(varchar(8), convert(time, '16:30:00'), 100) formatted_col from mytable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM