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…

php function calculate last day of month

php function calculate last day of month

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);

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>