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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference of two datestamps 1

Status
Not open for further replies.

halfbarrel

Programmer
Jun 12, 2002
44
US
Hello,
In MySql 4.1 how do you find the difference(preferrably int hours/minutes) of two dates? I see in 5.0 there is a timestampdiff function.
Thanks,

Chris.
 
DATEDIFF() returns the number of days between the start date expr and the end date expr2. expr and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation. TIMEDIFF() returns the time between the start time expr and the end time expr2. expr and expr2 are time or date-and-time expressions, but both must be of the same type.
Examples:

SELECT DATEDIFF('1997-12-31 23:59:59','1997-12-30');
-> 1

SELECT DATEDIFF('1997-11-31 23:59:59','1997-12-31');
-> -30

SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:01 00:00:00.000001');
-> '-00:00:00.000001'

SELECT TIMEDIFF('1997-12-31 23:59:59.000001','1997-12-30 01:01:01.000002');
-> '46:58:57.999999'

Dodge20
 
dodge20

How would you say with current date for one of these dates

DATEDIFF('1997-12-31 23:59:59','1997-12-30');

please?
 
mysql> select DATEDIFF(curdate(),'1997-12-30');

+----------------------------------+
| DATEDIFF(curdate(),'1997-12-30') |
+----------------------------------+
| 3005 |
+----------------------------------+


Dodge20
 
Sorry to trouble you further, Dodge20, but how could I use this in a php/mysql webpage? I've tried putting my number in a field in a db, and calling that up with a select query containing your code, but that just returns an empty set ....


SELECT DATEDIFF(curdate(),bulletin) FROM table;
 
Sorry I don't know any php.

Try your question here forum434

Dodge20
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top