ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

PHP code to get total number of days in a month

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.

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

PHP Basic Programs »

ADVERTISEMENT




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.