Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Time Format issues Expand / Collapse
Author
Message
Posted Thursday, February 13, 2014 8:40 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 13, 2014 9:43 AM
Points: 1, Visits: 3
pulling from a ms-dos csv file, time format is just numbers, no ":"
if event time is 145345 it shows as 145345, if it is 23 seconds after midnight it shows as 23
How do I convert or substring it to read 000023?
Post #1541246
Posted Thursday, February 13, 2014 8:52 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 9:14 PM
Points: 564, Visits: 851
You can try this:
declare @timevar int

select @timevar = '145345'

select right('000000' + cast(@timevar as varchar(6)), 6)

select @timevar = '23'

select right('000000' + cast(@timevar as varchar(6)), 6)





Microsoft Certified Master - SQL Server 2008
Follow me on twitter: @keith_tate

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1541252
Posted Thursday, February 13, 2014 9:00 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 3,313, Visits: 7,151
I'd go a little further and get the data as time.
declare @timevar int

select @timevar = '145345'

select CAST( STUFF( STUFF( right('000000' + cast(@timevar as varchar(6)), 6), 5, 0, ':'), 3, 0, ':') AS time)

select @timevar = '23'

select CAST( STUFF( STUFF( right('000000' + cast(@timevar as varchar(6)), 6), 5, 0, ':'), 3, 0, ':') AS time)




Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1541259
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse