calculate working hours

someone has an example of calculating hours worked using a SQL query

thanks for any help

Make two new date objects from the sql query.

Dim BeginDate as new Date
BeginDate.SQLDatetime= // “2015-09-03 16:13:32”

Dim EndDate as new Date
BeginDate.SQLDatetime= // “2015-09-03 08:13:32”

Dim DateDifference as Double
DateDifference = EndDate.TotalSeconds - BeginDate.TotalSeconds

Dim DiffDate as new Date
DiffDate.TotalSeconds = DateDifference

If you want to go the pure SQL (mySQL in this case) route the query would look something like this:

SELECT TIME_TO_SEC(TIMEDIFF(NOW(), timestamp_field))/3600 AS hourdiff FROM table_name

Replace NOW() with another timestamp if you don’t want to do the calculation based on the current SQL server time.