This function seems to only return false. Are any of you getting the same? I'm sure I'm overlooking something, however, fresh eyes and all that ...
function isweekend($date){ $date = strtotime($date); $date = date("l", $date); $date = strtolower($date); echo $date; if($date == "saturday" || $date == "sunday") { return "true"; } else { return "false"; } }
I call the function using the following:
$isthisaweekend = isweekend('2011-01-01');
Use the getDay() method to check if a date is during the weekend, e.g. date. getDay() === 6 || date. getDay() === 0 . The method returns a number between 0 and 6 for the day of the week, where Sunday is 0 and Saturday is 6 .
If you have PHP >= 5.1:
function isWeekend($date) { return (date('N', strtotime($date)) >= 6); }
otherwise:
function isWeekend($date) { $weekDay = date('w', strtotime($date)); return ($weekDay == 0 || $weekDay == 6); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With