trying to figure the following out :
I have a club that runs 3 days a week, Tuesday, Thursday and Saturday.
I want to print out the next club date from this week, so if Tuesday is the next meeting print out "Tuesday" or if today is Tuesday, print "Today", same for Thursday and Saturday.
I have the following code :
<?php
$current = date('l', strtotime('now'));
$tuesday = date('l', strtotime('tuesday this week'));
$thursday = date('l', strtotime('thursday this week'));
$saturday = date('l', strtotime('saturday this week'));
if ($tuesday < $current) {
echo "Tuesday in the future";
} else if ($thursday < $current) {
echo "Thursday in the future";
} else if ($saturday < $current) {
echo "Saturday in the future";
}
?>
And this is where i fell short and couldn't figure it out....as it always just prints "Tuesday in the future".
Any help, suggestions or explanations would be grealy welcome!
Thanks E
You are comparing string with date('l'). Change date('l') with date('Ymd'), or just leave strtotime, then you can compare numbers. You may need a "tuesday next week" if sunday.
<?php
$current = strtotime('now');
$tuesday = strtotime('tuesday this week');
$thursday = strtotime('thursday this week');
$saturday = strtotime('saturday this week');
$nextTuesday = strtotime('tuesday next week');
if ($tuesday > $current) {
echo "Tuesday in the future";
} else if ($thursday > $current) {
echo "Thursday in the future";
} else if ($saturday > $current) {
echo "Saturday in the future";
} else if($nextTuesday > $current) {
echo "Tuesday in the future";
}
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