1 | initial version |
Sure, here are some examples of how to create a DateTimeImmutable object on a monthly basis:
$now = new DateTimeImmutable();
$month = $now->format('Y-m-d');
echo $month;
// Output: 2022-12-01
$date = new DateTimeImmutable('2023-01-01');
$month = $date->format('Y-m-d');
echo $month;
// Output: 2023-01-01
$last_day_of_month = new DateTimeImmutable('last day of this month');
$month = $last_day_of_month->format('Y-m-d');
echo $month;
// Output: 2022-12-31
$first_day_of_next_month = new DateTimeImmutable('first day of next month');
$month = $first_day_of_next_month->format('Y-m-d');
echo $month;
// Output: 2023-01-01