note 17497 added to ref.datetime

From: Date: Tue, 11 Dec 2001 20:01:45 +0000
Subject: note 17497 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-22514@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 --- -- http://www.php.net/manual/en/ref.datetime.php http://master.php.net/manage/user-notes.php?action=edit+17497 http://master.php.net/manage/user-notes.php?action=delete+17497 http://master.php.net/manage/user-notes.php?action=reject+17497

« previous php.notes (#22514) next »