there is such a code to calculate the number of days between two dates:
$datetime1 = date_create("2018-10-01"); $datetime2 = date_create("2018-10-31"); $interval = date_diff($datetime1, $datetime2); $diff = $interval->format('%d'); for($i = 0; $i <= $diff; $i++){ $arr_days[] = date("dmY", strtotime("2018-10-01 +$i day")); } var_dump($arr_days);
With this, I run every day of the year (I use the t modifier, in the code, the date is just an example), but the code does not work for all months.
1,2,4,6,8,9,11 months working as it should
at 3,5,7,10,12 months in the array only one element - the first day of the month.
only the 3rd month excelled, for some 3 days it got into an array.
If you enter 30 instead of 31, then everything will work fine, but this month there are 31 days.
PHP 5.6.3
behavior is not at all obvious, why is this happening? Are there any more reliable means of calculating dates?