Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Text to Time

Author  Topic 

funk.phenomena
Posting Yak Master

121 Posts

Posted - 2013-09-19 : 16:53:04
Hi there - I have the following time value column in a table:

next_run_time
230000
73000
70000


The above actually translates to 23:00, 7:00AM,7:30AM, etc. How can I convert this into a meaningful time value?

[CODE]
SELECT NEXT_RUN_TIME FROM TABLE T1
[CODE]

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-09-19 : 17:01:25
Cast it as time (or datetime) after formatting it to a literal string acceptable to time (or datetime)
CAST(STUFF(CAST(YourIntegerColumn/10 AS VARCHAR(16)),3,0,':') AS TIME)
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-19 : 18:24:28
select
cast
(
cast(right('0'+reverse(substring(reverse(next_run_time),5,2)),2) as char(2)) + ':' +
cast(reverse(substring(reverse(next_run_time),3,2)) as char(2)) + ':' +
cast(right(next_run_time,2) as char(2)) as time
)
from
(
values
('230000'),
('73000'),
('70000'),
('230520'),
('70001')
)d(next_run_time);

Go to Top of Page
   

- Advertisement -