note 94071 added to function.date
| From: | dev at omikrosys dot com | Date: | Thu, 15 Oct 2009 06:14:48 +0000 |
| Subject: | note 94071 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161748@lists.php.net to get a copy of this message | ||
1. Find whether an year is a leap year or not.
2. Find the number of days in a given month of a year.
code -
function leapYear($year){
if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 != 0)) return TRUE;
return FALSE;
}
function daysInMonth($month = 0, $year = ''){
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$d = array("Jan" => 31, "Feb" => 28, "Mar" => 31,
"Apr" => 30, "May" => 31, "Jun" => 30, "Jul" =>
31, "Aug" => 31, "Sept" => 30, "Oct" => 31, "Nov"
=> 30, "Dec" => 31);
if(!is_numeric($year) || strlen($year) != 4) $year = date('Y');
if($month == 2 || $month == 'Feb'){
if(leapYear($year)) return 29;
}
if(is_numeric($month)){
if($month < 1 || $month > 12) return 0;
else return $days_in_month[$month - 1];
}
else{
if(in_array($month, array_keys($d))) return $d[$month];
else return 0;
}
}
You can call the function as daysInMonth(02, 2008); or daysInMonth('Feb', 2008);
If no year is specified then the current year will be used/shown.
----
Server IP: 59.162.86.2
Probable Submitter: 59.93.212.10
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/94071
Del: integrated -- https://master.php.net/note/delete/94071/integrated
Del: useless -- https://master.php.net/note/delete/94071/useless
Del: bad code -- https://master.php.net/note/delete/94071/bad+code
Del: spam -- https://master.php.net/note/delete/94071/spam
Del: non-english -- https://master.php.net/note/delete/94071/non-english
Del: in docs -- https://master.php.net/note/delete/94071/in+docs
Del: other reasons-- https://master.php.net/note/delete/94071
Reject -- https://master.php.net/note/reject/94071
Search -- https://master.php.net/manage/user-notes.php