Example 1 — Days in Different Months
Ask for the length of a few Gregorian months, including February in a leap year and in a normal year.
<?php
echo cal_days_in_month(CAL_GREGORIAN, 1, 2024), PHP_EOL;
echo cal_days_in_month(CAL_GREGORIAN, 2, 2023), PHP_EOL;
echo cal_days_in_month(CAL_GREGORIAN, 2, 2024), PHP_EOL;
echo cal_days_in_month(CAL_GREGORIAN, 4, 2024), PHP_EOL; How It Works
- CAL_GREGORIAN tells PHP to use the normal Gregorian calendar.
- January has 31 days, and April has 30 days.
- February 2023 has 28 days because 2023 is not a leap year.
- February 2024 has 29 days because 2024 is a leap year.

