Dan Bridgland
2008-05-30 09:52:53 UTC
Hi,
I'm working on a time card system for employees, I'm trying to
calculate the difference between two time values, one is a datetime
column (time_store.stamp) the other is a varchar column
(employees.contracted_to_time)
If I calculate the difference in seconds minutes or hours I get an
integer value of the difference eg:
-64
-28
33
18
-27
-87
But I need to turn this value back into a format of time of Hours,
minutes and seconds (hh:mm:ss) When I try to convert negative values
appear as
-2:-4
-1:28
0:33
0:18
-1:27
-2:27
I expect to see
-0:04
-0:28
0:33
0:18
-0:27
-1:27
How can I turn the minutes value into a valid time format?
this is the code im using
(CONVERT(varchar, FLOOR((DATEDIFF(MINUTE,(MIN( CONVERT(char(12),
EMPLOYEES.CONTRACTED_TO_TIME, 108))),(MAX( CONVERT(char(12),
TIME_STORE.STAMP, 108))))) / 60.0 )) + ':'
+ RIGHT('0' + CONVERT(varchar, (DATEDIFF(MINUTE,
(MIN( CONVERT(char(12), EMPLOYEES.CONTRACTED_TO_TIME, 108))),
(MAX( CONVERT(char(12), TIME_STORE.STAMP, 108))))) % 60), 2)) AS
CONTRACTED_TO_DIFF_IN_HOURS_AND_MINUTES,
Regards
Dan
I'm working on a time card system for employees, I'm trying to
calculate the difference between two time values, one is a datetime
column (time_store.stamp) the other is a varchar column
(employees.contracted_to_time)
If I calculate the difference in seconds minutes or hours I get an
integer value of the difference eg:
-64
-28
33
18
-27
-87
But I need to turn this value back into a format of time of Hours,
minutes and seconds (hh:mm:ss) When I try to convert negative values
appear as
-2:-4
-1:28
0:33
0:18
-1:27
-2:27
I expect to see
-0:04
-0:28
0:33
0:18
-0:27
-1:27
How can I turn the minutes value into a valid time format?
this is the code im using
(CONVERT(varchar, FLOOR((DATEDIFF(MINUTE,(MIN( CONVERT(char(12),
EMPLOYEES.CONTRACTED_TO_TIME, 108))),(MAX( CONVERT(char(12),
TIME_STORE.STAMP, 108))))) / 60.0 )) + ':'
+ RIGHT('0' + CONVERT(varchar, (DATEDIFF(MINUTE,
(MIN( CONVERT(char(12), EMPLOYEES.CONTRACTED_TO_TIME, 108))),
(MAX( CONVERT(char(12), TIME_STORE.STAMP, 108))))) % 60), 2)) AS
CONTRACTED_TO_DIFF_IN_HOURS_AND_MINUTES,
Regards
Dan