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.
Author |
Topic |
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-02-11 : 09:20:39
|
Hi,Imagine I have a field called field1 as varchar(50)Let's say it coontains seconds i.e. 173136.67This should represent (173136.67/3600) = 48.09 hoursHow can I convert to day:hour:min:seci.e. 02:??:??...At present I am using the following query but it shows an incorrect resultselect LEFT(RIGHT(CONVERT(VARCHAR(23), DATEADD(SECOND, 173136.67, 0), 121), 12),8)shows: 00:05:36Any thoughts please?Thanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-02-11 : 09:36:40
|
[code]select convert(varchar(10), datediff(day, 0, dateadd(second, 173136.67, 0))) + ':' + convert(varchar(10), dateadd(second, 173136.67, 0), 108) as ddhhmmss[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-11 : 09:40:17
|
declare @t decimal(5,2)set @t=48.09select DATEDIFF(DAY,0,DATE),CONVERT(char(12),date,108) from(select DATEADD(second,cast(@t as int)*3600+(@t*100%100)*60,0) as date) as tMadhivananFailing to plan is Planning to fail |
 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-02-11 : 09:47:20
|
Solved.Thank you all. |
 |
|
|
|
|
|
|