note 81275 deleted from function.mktime by derick

From: Date: Sat, 26 Jul 2008 10:06:45 +0000
Subject: note 81275 deleted from function.mktime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142776@lists.php.net to get a copy of this message
Note Submitter: JSantilln elquenovotoporfox at hotmail ---- <?php //Beware of this when comparing dates: function daysBetween($date1, $date2) { $d1 = explode("-", $date1); $d2 = explode("-", $date2); $year1 = $d1[0]; $month1 = $d1[1]; $day1 = $d1[2]; $year2 = $d2[0]; $month2 = $d2[1]; $day2 = $d2[2]; $deadline1 = mktime(0, 0, 0, $month1, $day1, $year1, 0); $deadline2 = mktime(0, 0, 0, $month2, $day2, $year2, 0); /* If you dont put 0 at last parameter both mktime calls, and a Daylight Saving Time is not specified, a float days number can be returned. Is better to pass 0 in both mktimes and round the result: */ $res = round( ($deadline2 - $deadline1) / (60 * 60 * 24) ); return $res; } /* My Test dates: */ echo daysBetween('2008-3-5','2008-3-11'); ?>

« previous php.notes (#142776) next »