Re: number of days in a month
| From: | Lars Torben Wilson | Date: | Tue, 29 Aug 2000 08:17:34 +0000 |
| Subject: | Re: number of days in a month | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14069@lists.php.net to get a copy of this message | ||
Jesper Juhl writes:
> I couldn't seem to get date() to return the number of days in a month, so
> I handled it like this:
[trim]
Try something like this:
<?php
error_reporting(E_ALL);
function days_in_month($month, $year) {
return date('t', mktime(0, 0, 0, $month, 1, $year));
}
echo "Days in February 1999: " . days_in_month(2, 1999) . "\n";
echo "Days in February 2000: " . days_in_month(2, 2000) . "\n";
echo "Days in February 2001: " . days_in_month(2, 2001) . "\n";
echo "Days in July 2001: " . days_in_month(7, 2001) . "\n";
?>
Hope this helps,
Torben
--
+----------------------------------------------------------------+
|Torben Wilson <torben@php.net> Netmill iTech|
|http://www.coastnet.com/~torben http://www.netmill.fi|
|Ph: 1 250 383-9735 torben@netmill.fi|
+----------------------------------------------------------------+