How to add hours to a timestamp?
Posted on 2006-05-18
I have a situation where I need to add hours to a timestamp. The only thing is that the hours could have .25 increments, with .25 representing 15 minutes.
My starting time will always be the same time such as 08:00 AM
If I needd to add the number 3.75 to this so that I end up with a time of 11:45AM how would I do this in my sql statement?
activity_dttm = '05/18/2006 8:00:00 AM'
IF I do
SELECT DATEADD(hour, 1.25, cast( sum(cast(activity_dttm as float) )as datetime))
then I ge the correct hour 11:00 AM but not the minutes of course. I know one way would be to parse my hour for either .00,.25,.50 or .75 since it can ONLY be one of those then set a variable = to either 0,15,30 or 45 to represent quarter of hours then do another Dateadd and add those minutes. I'm just wondering if there is a way to do it in a sql statement.