note 74132 added to function.date

From: Date: Mon, 26 Mar 2007 21:00:46 +0000
Subject: note 74132 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-124827@lists.php.net to get a copy of this message
I was tired of running into problems with Daylight Saving Time for calculating the date difference between two dates using timestamps. After all, I don't even care about the times. I only care about the dates. Here is a function using a simple algorithm to calculate the number of days since around the year 1 A.D. for the Gregorian calendar. This function can then be used to calculate the date difference between two dates. <?php function dayCount($y, $m, $d) { $m = ($m+9)%12; $y = $y-(int)($m/10); return 365*$y+(int)($y/4)-(int)($y/100)+ (int)($y/400)+(int)(($m*306+5)/10)+$d-1; } $dateDiff = dayCount(2007, 3, 18) - dayCount(2007, 3, 10); // Add 1 for an inclusive difference $dateDiff += 1; // Output is 9 ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.2.234.66 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/74132 Del: integrated -- https://master.php.net/note/delete/74132/integrated Del: useless -- https://master.php.net/note/delete/74132/useless Del: bad code -- https://master.php.net/note/delete/74132/bad+code Del: spam -- https://master.php.net/note/delete/74132/spam Del: non-english -- https://master.php.net/note/delete/74132/non-english Del: in docs -- https://master.php.net/note/delete/74132/in+docs Del: other reasons-- https://master.php.net/note/delete/74132 Reject -- https://master.php.net/note/reject/74132 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124827) next »