Home » Php » php – cal_days_in_month () function is not working

php – cal_days_in_month () function is not working

Posted by: admin July 12, 2020 Leave a comment

Questions:

This cal_days_in_month() is not working in PHP version 5.2.11

$days_in_month = cal_days_in_month(0,$month,$year);
How to&Answers:

Try

date('t', mktime(0, 0, 0, $month, 1, $year)); 

And I found in internet that it require PHP to compile with calender support.

“recompile php with the “–enable-calendar” option.”

Answer:

you need to provide calendar :

int cal_days_in_month ( int $calendar , int $month , int $year )

like:

$month_length = cal_days_in_month(CAL_GREGORIAN, $month, $year); 

you maybe confusing it with cal_info ([ int $calendar = -1 ] )
which takes a representation of the calendar :

0 or CAL_GREGORIAN - Gregorian Calendar
1 or CAL_JULIAN - Julian Calendar
2 or CAL_JEWISH - Jewish Calendar
3 or CAL_FRENCH - French Revolutionary Calendar

Answer:

Because syntax is :

$days_in_month = cal_days_in_month(CALENDAR,$month,$year);

like this :

$days = cal_days_in_month(CAL_GREGORIAN, 2, 2012);