Using date() and strtotime() to Set a Delivery or Shipping Date

Scenario: Let’s say your business ships products out every Monday, but the cut off date for ordering for the next delivery date is Thursday. This snippet checks the day of the week with date(‘w’). (It can also be accomplished by using l, D, or N.) Then, if it’s past a certain day of the week, it will set $delivery to be the following Monday.

Example Using date(‘w’)

if ( date('w') > 4) {
    // Note: Sunday = 0
    // Wait til next Monday!
    $delivery = date('l, F jS, Y', strtotime('next Monday + 1 week', time()));
} else {
    // They get it this coming Monday!
    $delivery = date('l, F jS, Y', strtotime('next Monday', time()));
}

echo "Your Delivery Date: $delivery";

Example Using date(‘l’)

if ( (date('l') === 'Friday') || (date('l') === 'Saturday') || (date('l') === 'Sunday') ) {
	// Wait til next Monday!
	$delivery = date('l F jS, Y', strtotime('next Monday + 1 week', time()));
} else {
	// They get it this coming Monday!
	$delivery = date('l F jS, Y', strtotime('next Monday', time()));
}

echo "Your Delivery Date: $delivery";

When working on this snippet, the part I struggled the most with was: strtotime(‘next Monday + 1 week’, time()). I knew that I could do strtotime(‘next Monday’, time()), and I knew I could do strtotime(‘+ 1 week’, time()), but at first I didn’t realize I could combine them like that.

Further Reading: