Cal_days_in_month () function not working

This cal_days_in_month() does not work in PHP version 5.2.11

 $days_in_month = cal_days_in_month(0,$month,$year); 
+4
source share
3 answers

Try

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

And I found on the Internet that he needed to compile PHP with calendar support.

"recompile php with the parameter" --enable-calendar ".

+19
source

you need to provide a calendar:

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

as:

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

you can confuse it with cal_info ([ int $calendar = -1 ] ) which takes a calendar view:

 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 
-one
source

Because the syntax is:

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

like this:

 $days = cal_days_in_month(CAL_GREGORIAN, 2, 2012); 
-3
source

Source: https://habr.com/ru/post/1395926/


All Articles