03 Dec 2012
php function calculate last day of month
In programming there are many occasions that we need to check last day of a month.
Occasions like running payroll, calculating inventory, and so many occasions like this…
Here I’m showing a simple php function calculate last day of month.
In this function you need to pass month and year. In return the function will return last day of the month.
function calclastdayofmonth($month=NULL,$year=NULL){
if ($month!='') {
$month = date('m');
}
if ($year!='') {
$year = date('Y');
}
$result = strtotime("$year-$month-01");
$result = strtotime('-1 day', strtotime('+1 month', $result));
return date('Y-m-d', $result);
}
//usage
echo calclastdayofmonth(11, 2012);
