I'm trying what should be a simple IF statement to show content if the day of the week is Saturday or Sunday. This statement always returns true.
<?php
if(date('D') == ('Sat' || 'Sun')) {
echo "Today is Saturday or Sunday.";
} else {
echo "Today is not Saturday or Sunday.";
}
?>
I also tried: (Sat || Sun)
and (Saturday || Sunday)
Any ideas here?
date('D') = Sun
php if(date('D') == 'Sat' || date('D') == 'Sun') { echo "Today is Saturday or Sunday."; } else { echo "Today is not Saturday or Sunday."; } ?> Output : Today is Saturday or Sunday.
PHP Code: <? php $dt='2011-01-04'; $dt1 = strtotime($dt); $dt2 = date("l", $dt1); $dt3 = strtolower($dt2); if(($dt3 == "saturday" )|| ($dt3 == "sunday")) { echo $dt3. ' is weekend'.
php $s = 'Monday, September 28, 2009'; $time = strtotime($s); $start = strtotime('last sunday, 12pm', $time); $end = strtotime('next saturday, 11:59am', $time); $format = 'l, F j, Y g:i A'; $start_day = date($format, $start); $end_day = date($format, $end); header('Content-Type: text/plain'); echo "Input: $s\nOutput: $ ...
This should solve it: $day = date('D'); $date = date('d') if($day == Mon){ //Code for monday } if($date == 01){ //code for 1st fo the month } else{ //not the first, no money for you =/ }
The issue is, you have to check the condition individually.
Try this:
<?php
if(date('D') == 'Sat' || date('D') == 'Sun') {
echo "Today is Saturday or Sunday.";
} else {
echo "Today is not Saturday or Sunday.";
}
?>
Explanation:
date()
function with 'D'
parameter will return the day like Sat
, Sun
etc
Output
: Today is Saturday or Sunday.
Working code
date() parameters list
You can also use date('N')
where Sat = 6 and Sun = 7
<?php
if(date('N') > 5) {
echo "Today is Saturday or Sunday.";
} else {
echo "Today is not Saturday or Sunday.";
}
?>
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