Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datediff replacement in MySQL

Status
Not open for further replies.

QatQat

IS-IT--Management
Nov 16, 2001
1,031
IT
Hi there,

here is my table
create table dailyregister (
recordid int,
SignedIn datetime,
SignedOut datetime
TotalTime ???)


TotalTime is calculated upon request of the operator and it should be equal to subtracting SIgnedOut - SignedIn.

What datatype is best suited for the job? I tried datetime as well but I only get 0000-00-00 00:00:00 results.

I need to get the time difference between those two fields (in seconds or minutes) and I found out that datediff ()function only works in MySQL 4.1.

How do I go around?

Thank you

QatQat


Life is what happens when you are making other plans.
 
In my opinion the best way to store moments such as SignedIn and SignedOut is as DATETIME values. These can be massaged as needed for display or calculation.

I think the late appearance of DATEDIFF() in MySQL is an oddity; we always need to calculate duration.

Possibly UNIX_TIMESTAMP( date ) can be used
Code:
SELECT UNIX_TIMESTAMP( SignedOut ) - UNIX_TIMESTAMP( SignedIn ) AS "SecondsOnDuty"

But see further

 
Thanks a lot;

that did it.


CHeers

QatQat

Life is what happens when you are making other plans.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top