Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Military time as regular time

I have a table I'm able to select on only
It has 2 columns and an id
the columns are in military time...but are varchar(200)

I need to do a select and output as regular time with a space and AM or PM

Example

ckin
1600

needs to be output at 4:00 PM
Avatar of MNelson831
MNelson831
Flag of United States of America image

Declare @Datafield as varchar(50)

Set @DataField = '1600'

select
      Case
            when left(@DataField,2) - 12 < 0 then Left(@DataField,2)
            Else Left(@DataField,2)
      End + ':' + right(@DataField,2)
OOps

Try this instead

Declare @Datafield as varchar(50)

Set @DataField = '1600'

select
      Case
            when left(@DataField,2) - 12 < 0 then Left(@DataField,2)
            Else Left(@DataField,2) -12
      End + ':' + right(@DataField,2)
ASKER CERTIFIED SOLUTION
Avatar of MNelson831
MNelson831
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial