note 54583 added to ref.datetime

From: Date: Fri, 08 Jul 2005 13:36:52 +0000
Subject: note 54583 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-91672@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54583 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54583&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54583&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91672) next »