note 54583 deleted from ref.datetime by derick
| From: | derick@php.net | Date: | Sun, 14 Aug 2005 12:05:17 +0000 |
| Subject: | note 54583 deleted from ref.datetime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93632@lists.php.net to get a copy of this message | ||
Note Submitter: szaboferenc at somogy dot hu
----
Many people need a solution for calculating the number of days between a stored MySQL timestamp and
the current time. A quick solution for this is here.
//pull your timestamp in a YYYY-mm-dd format:
$result = mysql_query("SELECT DATE_FORMAT(YOUR_TIMESTAMP_DATE,'%Y-%m-%d') FROM
fTable";); $data = mysql_fetch_row($result2);
//generate a date for the current time
$ma=date('Y-m-d')
//convert and calculate:
$datefrom = strtotime($data[0], 0);
$dateto = strtotime($ma, 0);
$difference = $dateto - $datefrom;
$datediff = floor($difference / 86400);
And now the $datediff gives you the number of days between the two dates.