note 6969 modified in date by ronabop

From: Date: Sat, 02 Sep 2000 21:41:06 +0000
Subject: note 6969 modified in date by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-3956@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 :-) http://www.php.net/manual/function.date.php

« previous php.notes (#3956) next »