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 |
|
alanmac
Starting Member
26 Posts |
Posted - 2011-07-22 : 07:43:37
|
| Hi, I have a time field in my database which stores data such as 14.30, 17.45, etc. What I need to do is get an integer from another field and add it to this time and return it in the same format, so that 14.15 plus 30 would return 14.45.Is this possible? |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2011-07-22 : 08:23:38
|
[code]Declare @t table ( tm decimal(5,2))Insert Into @t Select 14.30Insert Into @t Select 17.45Insert Into @t Select 23.45Declare @mn intSet @mn = 30Select tm, OneWay = convert(decimal(5,2),stuff(left(convert(varchar,dateadd(n,floor(floor(tm)*60 + tm*100%100)+@mn,35624),108),5),3,1,'.')), Another = convert(decimal(5,2),((floor(tm)+floor((tm*100%100+@mn)/60))%24+24)%24 + (((tm*100%100+@mn)%60+60)%60)/100)From @t[/code]Corey I Has Returned!! |
 |
|
|
alanmac
Starting Member
26 Posts |
Posted - 2011-07-22 : 08:37:13
|
| Many thanks. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-07-25 : 06:54:13
|
orselect convert( varchar(10), dateadd(minute,(floor(tm)*60+tm%1*100)+@mn,0), 108 ) from @t MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|