I have a very complicated delivery situation with a switch statement that is checking day of the week and a cutoff time of 16:00 everyday and echo's out the delivery day which on Monday, Tuesday and Wednesday is todays day + 1 day if post cut off it should echo todays date + 2, thursdays and fridays have completely different delivery days due to the none delivery on weekends
<?php
$today = date("D");
switch($today){
case "Mon":
if(mktime(16, 0, 0) <= time()) {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 2 days')) . "</strong><p>";
} else {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 1 days')). "</strong><p>";
}
break;
case "Tue":
if(mktime(16, 0, 0) <= time()) {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 2 days')). "</strong><p>";
} else {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 1 days')). "</strong><p>";
}
break;
case "Wed":
if(mktime(16, 0, 0) <= time()) {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 2 days')). "</strong><p>";
} else {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 1 days')). "</strong><p>";
}
break;
case "Thu":
if(mktime(16, 0, 0) <= time()) {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 4 days')). "</strong><p>";
} else {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 1 days')). "</strong><p>";
}
break;
case "Fri":
if(mktime(16, 0, 0) <= time()) {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 5 days')). "</strong><p>";
} else {
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 4 days')). "</strong><p>";
}
break;
case "Sat":
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 4 days')). "</strong><p>";
break;
case "Sun":
echo "<p>For Delivery on <strong> " . date('D jS', strtotime($Date. ' + 3 days')). "</strong><p>";
break;
default:
echo "No information available for that day.";
break;
}
?>
surely they must be a more elegant way of achieving this, would any body know of a cleaner way of achieving the same result. This code works but could be alot better and shorter