PHP: Check if any date falls on weekend
$PDATEX = '2020-06-21'; if( (date('N', strtotime($PDATEX)) >= 6)) {echo 'Wowwwwwwwwwwwww';} else{echo 'Ooooops';}
Definition and Usage
Above code takes date as parameter and checks the day no (The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday))
w can also be used instead of N if unix day no is required. (w - A numeric representation of the day (0 for Sunday, 6 for Saturday).
You can echo any text of any function to further utilize code in your application.
Below function can be used for reference
$PDATEX = '2019-02-17'; function WeekendChk($PDATEX) { return (date('N', strtotime($PDATEX)) >= 6); } if (WeekendChk($PDATEX)){echo 'Wowwwwwwwwwwwww';};
Related Study
Loop, While loop, if elseif else, strtotime function, date function, date reference