MikeM670
asked on
Convert int to military time
How do I convert and int to military time?
example:
Int
7 = 0700
19 = 1900
23 = 2300
example:
Int
7 = 0700
19 = 1900
23 = 2300
If it is just the hours then:
Basically multiply by 100 and prefix with a 0 and return the right 4 chars
select right('0' + cast((colname * 100) as nvarchar(2)), 4)
Basically multiply by 100 and prefix with a 0 and return the right 4 chars
ASKER
Victor,
Yes it's only for the hours. I'm using a stored procedure that uses:
SET @8hrfirstshiftstart = 7
SET @8hrfirstshiftend = 15
ect....
to find the start and end of shifts. But I want to return the 7 or other values from the stored procedure to use as labels in crystal reports.
Like this...
0700 - 1500
Yes it's only for the hours. I'm using a stored procedure that uses:
SET @8hrfirstshiftstart = 7
SET @8hrfirstshiftend = 15
ect....
to find the start and end of shifts. But I want to return the 7 or other values from the stored procedure to use as labels in crystal reports.
Like this...
0700 - 1500
Try.. Easiest One :)
trial
Output
DECLARE @T AS INT = '7'
SELECT LEFT(@t * 1000,4)
trial
DECLARE @T AS INT = '7'
SELECT LEFT(@t * 1000,4)
GO
DECLARE @T AS INT = '19'
SELECT LEFT(@t * 1000,4)
GO
DECLARE @T AS INT = '23'
SELECT LEFT(@t * 1000,4)
GO
DECLARE @T AS INT = '1'
SELECT LEFT(@t * 1000,4)
Output
----
7000
(1 row(s) affected)
----
1900
(1 row(s) affected)
----
2300
(1 row(s) affected)
----
1000
(1 row(s) affected)
ASKER
Pawan,
Unfortunately that won't work for time values like
7 = 0700
1 = 0100
Unfortunately that won't work for time values like
7 = 0700
1 = 0100
----
7000
(1 row(s) affected)
----
1900
(1 row(s) affected)
----
2300
(1 row(s) affected)
----
1000
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lee,
Returns a error:
Arithmetic overflow error converting expression to data type nvarchar
Arithmetic overflow error converting expression to data type nvarchar
Returns a error:
Arithmetic overflow error converting expression to data type nvarchar
ASKER
That is exactly what I needed. Thanks!
If so you can try this:
Open in new window