note 6969 deleted from function.date by jimw
| From: | jimw@php.net | Date: | Fri, 02 Nov 2001 00:39:31 +0000 |
| Subject: | note 6969 deleted from function.date by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-20045@lists.php.net to get a copy of this message | ||
SOLUTION: Calculate the day difference between 2 dates
A few people have been asking about this so i'll share my solution:
I have some dates stored in a MySQL database in the format 'yyyy-mm-dd'
I wanted to find the difference between those dates and the current date in whole days.
Note: you could calculate the difference in months just as easily.
// Routine to display the difference between two dates
// Date stored in the MySQL database as yyyy-mm-dd
$today=date("Y-m-d 00:00");
$date1=strtotime( "2000-07-22 00:00" );
// The date value [2000-07-23] here would be the retrieved mysql string
$date2=strtotime($today);
echo "Difference: ".(($date2-$date1)/86400);
// Prints number of days difference
Other notes added to the PHP manual have helped me a lot, so i thought i'd do my part :-)