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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Calcualting time

Author  Topic 

pmccann1
Posting Yak Master

107 Posts

Posted - 2007-03-19 : 12:20:59
I two fields both are data type float. One is a start time the other is a finishing time (both are 24hr time) i was wondering is there a way of taking one from the other i.e to find the length of time something takes. the problem occurs when say the start time is,22.10 and finish time is 0.20. am i able to change this or what is the best way to go about it

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-19 : 12:24:14
DATEDIFF function.
Use second as datepart parameter and divide by 3600.0 to get fraction of hours.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-03-19 : 13:47:15
What if the duration is longer than 24 hrs?

With the data you have you will need a conditional to check if the end time is before the start and if so add a day to it - but if the duration is longer than 24 hrs there's no way of telling.

It depends on what your floats represent as to how you would calculate beyond that. Probably converting to a datetime then just subtracting would be easiest.

If your 0.20 is 00:20:00 then probably convert to character, replace . by : and convert to datetime would work.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -