|
The data I get is in text from the DB (74125 for 7:41:25) I need to take the start and end times and calculate the hh:mm:ss what is the best approach in SQL Server 2008 R2. Start End ElapsedTime 70500 71002 00:05:02 Thanks ****UPDATE**** I just noticed the time is not string but it is being stored as int.
(comments are locked)
|
|
In this example I show the intermediate steps to show, but you don't need to include these... gives
(comments are locked)
|
|
This should run on any version. --First the integer version --And now the string version @Phil factor Nice.. Liked the STUFFs stuff :) But I guess the code could get shorten quite a bit....? Also, two very good answers but just wandering what about handling more than 24 hours time span? :) NULL values handling could always be user's discrestion.
Apr 27 '12 at 01:37 PM
robbin
@robbin. Yes, I'd forgotten about the Date and Time Style no. 8 I felt so ashamed, I went and altered the code. Yours works fine, but was originally worried I might be taken to task for doing a direct subtraction of one datetime from another!
Apr 27 '12 at 02:23 PM
Phil Factor
I've added in the integer version
Apr 27 '12 at 05:15 PM
Phil Factor
(comments are locked)
|
|
The measurement is a daily query. The activity is measured with the getdate() of that dady only so it all will be under 24 hours. The users are pulling orders within a time period. if anything could check if > 1800 since they would never go past that time daily. I just noticed the time is not string but it is being stored as int.
Apr 27 '12 at 03:42 PM
jaymz69
(comments are locked)
|
|
I just noticed the time is not string but it is being stored as int. I've added an integer solution
Apr 27 '12 at 05:16 PM
Phil Factor
(comments are locked)
|
|
So now I get this error when I change the variables to int Msg 242, Level 16, State 3, Line 10 The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. That error matches the query I am using for the real data too
(comments are locked)
|
1 2 next page »

