SQL - Time String to Military Time

1.8k Views Asked by At

I have a field named timecompleted that is of type varchar that holds standard time values with either " am" or " pm" after the time. The problem I'm having is that I need to convert this to military time in a Select statement.

So for example, if my time value is "2:23:44 pm" I need it to be translated to "14:23:44", etc... (which is HH:MM:SS in military time).

How would I accomplish this easily in a select statement?

1

There are 1 best solutions below

0
On BEST ANSWER

EDIT: Assuming SQl Server.

If so, you can simply cast your string as TIME

Select cast('2:23:44 pm' as time)

Returns

14:23:44.0000000