// Created on savesnippets.com · https://savesnippets.com/ZMPyAx6CEgskYF setTime(0, 0, 0); } function endOfDay(DateTimeImmutable $d): DateTimeImmutable { return $d->setTime(23, 59, 59); } function startOfMonth(DateTimeImmutable $d): DateTimeImmutable { return startOfDay($d->modify('first day of this month')); } function endOfMonth(DateTimeImmutable $d): DateTimeImmutable { return endOfDay($d->modify('last day of this month')); } function startOfWeek(DateTimeImmutable $d, string $start = 'monday'): DateTimeImmutable { $dow = (int)$d->format('N'); // 1=Mon … 7=Sun $target = $start === 'sunday' ? 7 : 1; $diff = ($dow - $target + 7) % 7; return startOfDay($d->modify("-$diff day")); } $now = new DateTimeImmutable('2025-03-12 14:25:00'); echo startOfMonth($now)->format('c'); // 2025-03-01T00:00:00+00:00 echo endOfDay($now)->format('c'); // 2025-03-12T23:59:59+00:00