|
-
Calculating time elapsed btwn two datetime fields
I'm trying to calculate the time elapsed (in HH:MM) between two DATETIME columns. I'm storing the result in another column with DATATYPE = TIME:
UPDATE table SET time_elapsed = later_datetime - earlier_datetime;
This is not working when the individual components of the DATETIME field in later_datetime (i.e. seconds, minutes, etc.) are lower than those in the earlier_datetime, as in the following example:
later_datetime = 2003-02-04 12:39:20
earlier_datetime = 2003-02-04 12:04:44
time_elapsed = 00:00:00
I think this is happening because MySQL deems the operation ilegal because the individual seconds in later_datetime (20) is less than the individual seconds in earlier_datetime (44).
Any suggestions as to how can I correctly calculate the time elapsed (in HH:MM) between two datetime fields?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|