Finding the difference in date...
Posted 07 April 2006 - 03:30 AM
Posted 07 April 2006 - 03:58 AM
How would I go about finding the difference between a date stored in the 'DATE' type in a MySQL database and the current date.. Just looking for how many days there are between the current date and what is stored in the database.
is it in timestamp?
// mysql timestamp from db
$old_timestamp = $row['date'];
// Time in seconds from then to right now
$elapsed_seconds = time() - $old_timestamp;
// divide by 60 for minutes, 60 for hours, then 24 for days, using floor to make an integer
$elapsed_days = floor(($elapsed_seconds / 60) / 60 / 24);
Posted 07 April 2006 - 04:08 AM
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.
mysql> SELECT DATEDIFF('1997-12-31 23:59:59','1997-12-30');
mysql> SELECT DATEDIFF('1997-11-30 23:59:59','1997-12-31');
DATEDIFF() was added in MySQL 4.1.1
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users