note 24390 modified in function.date by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Thu, 15 Aug 2002 02:31:32 +0000 |
| Subject: | note 24390 modified in function.date by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-35049@lists.php.net to get a copy of this message | ||
[Editor's note: You can also use the simpler function call: date("t"). See the date()
functions for more details.]
Here is a quick little script I made up to find the number of days in a given month (in the given
year). Please tell me if you find any mistakes in it, but to me it seems like it works well:
function numDays($month,$year)
{
// Returns the number of days in a $month, in the given $year.
// Checks for a leap year.
if ((!strstr($year/4,"."))&&(substr(2,4,$year)!=00)){
$leapyear = 1;}
if(substr(2,4,$year)==00){
if(!strstr($year/400,".")){
$leapyear = 1;}
}
switch($month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
$total_days = 31;
break;
case 4:
case 6:
case 9:
case 11:
$total_days = 30;
break;
case 2:
if ($leapyear)
{
$total_days = 29;
}
else
{
$total_days = 28;
}
break;
default:
break;
}
return $total_days;
}
--was--
Here is a quick little script I made up to find the number of days in a given month (in the given
year). Please tell me if you find any mistakes in it, but to me it seems like it works well:
function numDays($month,$year)
{
// Returns the number of days in a $month, in the given $year.
// Checks for a leap year.
if ((!strstr($year/4,"."))&&(substr(2,4,$year)!=00)){
$leapyear = 1;}
if(substr(2,4,$year)==00){
if(!strstr($year/400,".")){
$leapyear = 1;}
}
switch($month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
$total_days = 31;
break;
case 4:
case 6:
case 9:
case 11:
$total_days = 30;
break;
case 2:
if ($leapyear)
{
$total_days = 29;
}
else
{
$total_days = 28;
}
break;
default:
break;
}
return $total_days;
}
http://www.php.net/manual/en/function.date.php