Re: Function mktime() documentation question
| From: | Tedd Sperling | Date: | Sun, 11 Mar 2012 01:38:26 +0000 |
| Subject: | Re: Function mktime() documentation question | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316978@lists.php.net to get a copy of this message | ||
On Mar 10, 2012, at 12:20 PM, Maciek Sokolewicz wrote:
> function getAmountOfDaysInAMonth($month, $year) {
> $days = array(31, (($year%4==0 and ($year%100 > 0 or $year%400==0)) ? 29 : 28), 31, 30,
> 31, 30, 31, 31, 30, 31, 30, 31);
> return $days[$month+1];
> }
I like that -- here's a small variation.
function numberDaysMonth($month, $year)
{
// Leap year is definded as a year that is evenly divisible by four
// AND (year NOT evenly divisible by 100 OR year IS evenly divisible by 400)
$feb = ($year%4 == 0 && ($year%100 != 0 || $year%400 == 0) ) ? 29 : 28;
$days = array(0, 31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
return $days[$month];
}
Cheers,
tedd
_____________________
tedd.sperling@gmail.com
http://sperling.com