How to check whether a date is a weekend
Short answer
The N character returns the day-of-week number: 1 is Monday, 7 is Sunday:
<?php
function isWeekend(string $date): bool
{
return (new DateTimeImmutable($date))->format('N') >= 6;
}
var_dump(isWeekend('2026-03-14'));
var_dump(isWeekend('2026-03-16'));Output:
bool(true)
bool(false)The next working day
The weekday expression skips Saturday and Sunday:
<?php
$friday = new DateTimeImmutable('2026-03-13');
echo $friday->modify('+1 weekday')->format('l, Y-m-d');Output:
Monday, 2026-03-16Functions used in this recipe
- date — Formats a date and time.
- DateTimeImmutable — A date and time object that cannot be changed: every operation returns a new object.
- in_array — Checks whether a value exists in an array.