Larry Brister
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
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
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)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set @DataField = '1600'
select
Case
when left(@DataField,2) - 12 < 0 then Left(@DataField,2)
Else Left(@DataField,2)
End + ':' + right(@DataField,2)