note 39150 added to function.cal-days-in-month

From: Date: Mon, 19 Jan 2004 02:12:22 +0000
Subject: note 39150 added to function.cal-days-in-month
Groups: php.notes 
Request: Send a blank email to php-notes+get-63807@lists.php.net to get a copy of this message
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); } ---- Manual Page -- http://www.php.net/manual/en/function.cal-days-in-month.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39150 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39150&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39150&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63807) next »