I have 2 dates like this YYYY-mm-dd and I would like to check if these 2 dates are a weekend.
I have this code but it only tests 1 date and I don't know how to adapt it; I need to add a $date_end
.
$date = '2011-01-01';
$timestamp = strtotime($date);
$weekday= date("l", $timestamp );
$normalized_weekday = strtolower($weekday);
echo $normalized_weekday ;
if (($normalized_weekday == "saturday") || ($normalized_weekday == "sunday")) {
echo "true";
} else {
echo "false";
}
You can use shorter code to check for weekend =>
date('N', strtotime($date)) >= 6
. So, to check for 2 dates — and not just 1 — use a function to keep your code simple and clean:Using your existing code, which is slightly longer, following is how you would check for 2 dates: