note 17497 deleted from ref.datetime by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:32:22 +0000 |
| Subject: | note 17497 deleted from ref.datetime by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23568@lists.php.net to get a copy of this message | ||
Here's a simple piece of code that returns the number of days, hours, mins and seconds to a
certain date and time... set the last value of maketime to 0 if you want to disable GMT. Does anyone
know a good way to count the number of months between the two dates? If you do, email me -
--- Begin code ---
$then = mktime($t_hr,$t_min,$t_sec,$t_month,$t_day,$t_year,-1);
$now = time();
if ($now > $then) {
$diff = ($now - $then);
} else {
$diff = ($then - $now);
}
$days = (int) ($diff / (60 * 60 * 24));
// We've accounted for x days
$diff = ($diff - ($days * 60 * 60 *24));
$hours = (int) ($diff / (60 * 60));
// We've accounted for x hours
$diff = ($diff - ($hours * 60 * 60));
$mins = (int) ($diff / 60);
// We've accounted for x mins
$diff = ($diff - ($mins * 60));
$secs = $diff;
--- End code ---