Q:

PHP code to get total number of days in a month

belongs to collection: PHP Basic Programs

0

Here is the PHP code to get total number of days in a month.

Method get_days_in_month() returns total number of days according to given month and year.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Source Code and Output to get total number of days in a month

<?php
$curmnth = date('m');
$curyear = date('Y');
function get_days_in_month($month, $year)
{
    if ($month == "02")
    {
        if ($year % 4 == 0) return 29;
        else return 28;
    }
    else if ($month == "01" || $month == "03" || $month == "05" || $month == "07" || $month == "08" || $month == "10" || $month == "12") return 31;
    else return 30;
}
$totDays = get_days_in_month($curmnth, $curyear);
printf("Total no of days in a current month : " . $totDays);
print "</br>";
?>

Output

Total no of days in a current month: 30

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How to break a foreach loop in PHP?... >>
<< PHP code to assign and print the current date time...