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: Yesterday @ 4:52 PM
Points: 590, Visits: 911
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: Yesterday @ 8:54 PM
Points: 3,637, Visits: 7,932
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.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

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