Re: number of days in a month

From: Date: Tue, 29 Aug 2000 07:57:47 +0000
Subject: Re: number of days in a month
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-14065@lists.php.net to get a copy of this message
> Jesper Juhl wrote: > > > > Hi, > > > > Is there an easy way in PHP4 to get the number of days in any given > > month? > > <skip>... > Hi! > There is function 'date()', which has a lot of nice formatting > possibilities > including number of days in given month. > See chapter 'IX. Date and Time functions' -> 'date()' from PHP manual. > Hope this helps. > -- > Pavel a.k.a. Papi > -- I couldn't seem to get date() to return the number of days in a month, so I handled it like this: switch ($month) { case 2: if ($year % 4 != 0) { $nr_days = 28; } else if ($year % 400 == 0) { $nr_days = 29; } else if ($year % 100 == 0) { $nr_days = 28; } else { $nr_days = 29; } break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: $nr_days = 31; break; case 4: case 6: case 9: case 11: $nr_days = 30; break; } But thank you for your reply! Best regards, Jesper Juhl juhl@eisenstein.dk

« previous php.general (#14065) next »