note 39150 deleted from function.cal-days-in-month by didou
| From: | didou@php.net | Date: | Tue, 27 Jan 2004 08:38:40 +0000 |
| Subject: | note 39150 deleted from function.cal-days-in-month by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-64234@lists.php.net to get a copy of this message | ||
Note Submitter: ben@sparkyb.net
----
I was checking your math, and it doesn't work out right. The mod 7, mod 2 thing is genius (I
too know the knuckles thing) but you are off by 1. remember that modulus wraps around to 0 whereas
the months start counting with 1. The fix is to subtract 1 so that you count from 0.
The revised function:
function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1)
% 7 % 2 ? 30 : 31);
}