PHP function to count days in current year

Custom function cal_days_in_year($year)

<?php 
 function cal_days_in_year($year){
    $days=0; 
    for($month=1;$month<=12;$month++){ 
        $days = $days + cal_days_in_month(CAL_GREGORIAN,$month,$year);
     }
 return $days;
}
echo cal_days_in_year(2017);
?>
Output : 365

2 thoughts on “PHP function to count days in current year”

  1. Since the number of days is fixed in the other months, you just need to know how many days February has in $year:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.