Here is a small function that returns the last day of a month of an year, both passed to it in the numerical form.
<?php
function getlastdayofmonth($month, $year)
{
for ($day = 28; $day < 33; $day++)
{
if (!checkdate($month, $day, $year))
return $day-1;
}
}
$l=getlastdayofmonth(2,2008);
echo 'Last day of Feb 2008: '.$l.'<br>';
$m=getlastdayofmonth(6,2010);
echo 'Last day of Jun 2010: '.$m.'<br>';
$n=getlastdayofmonth(12,2010);
echo 'Last day of Dec 2010: '.$n.'<br>';
?>
Output:
Last day of Feb 2008: 29
Last day of Jun 2010: 30
Last day of Dec 2010: 31
<?php
function getlastdayofmonth($month, $year)
{
for ($day = 28; $day < 33; $day++)
{
if (!checkdate($month, $day, $year))
return $day-1;
}
}
$l=getlastdayofmonth(2,2008);
echo 'Last day of Feb 2008: '.$l.'<br>';
$m=getlastdayofmonth(6,2010);
echo 'Last day of Jun 2010: '.$m.'<br>';
$n=getlastdayofmonth(12,2010);
echo 'Last day of Dec 2010: '.$n.'<br>';
?>
Output:
Last day of Feb 2008: 29
Last day of Jun 2010: 30
Last day of Dec 2010: 31
Comments
Post a Comment