Get the number of days in a month

Comments Off
Identi.ca
Share
calendar
Photo : Dafne Cholet

Ever wonder how many days there are in a specific month ?

Your quest is over, I have what you need : the cal_days_in_month() function from the Calendar PHP extension. This function can work with different calendars : gregorian, julian, jewish… Then just specified a month of a particular year and it will return the number of days :

$days = cal_days_in_month(CAL_GREGORIAN, 2, 2024);
echo $days; // output : 29

$days = cal_days_in_month(CAL_GREGORIAN, date('n'), date('Y'));
echo $days; // output : 30

To list the available calendars, you may use cal_info() :

print_r(cal_info());

See “sources” links for more informations :)

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Sources :

Comments are closed.

About The Author

maximem

I'm a french web developer co-managing a little web agency named Wixiweb in the north of France. I have about 6 years of working experience with PHP and I'm a Zend Framework Certified Engineer.

Post Tags