How to calculate number of days in a month or a year in php

 <?php 

$curmnth = date('8'); //AUGUST

$curyear = date('Y'); //2023

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

echo $totDays; //31 Days

?>

0 Comments