Jump to content

Add 3 days to date


toolman

Recommended Posts

Hi,

 

I'm trying to create a simple bit of PHP that will display today's date +3 days.

 

This is what I have:

 

echo "Order today to receive by " . date("l j F Y")+3;

 

I am new to PHP, but what I am trying to do is to add 3 days to a date is the day is a week day and add 5 days if the day is a weekend.

 

How would I achieve this?

Link to comment
Share on other sites

Or you could use DateTime() ->

<?php

$variableDate = "October 8, 2017";

/*
 * DateTime & DateTimezone are classes built into PHP.
 */
$myDate = new DateTime($variableDate, new DateTimeZone("America/Detroit"));

/*
 *  N is a numeric representation -> 1 (for Monday) through 7 (for Sunday)
 */
if ( $myDate->format("N") < 6) {
    $myDate->modify("+3 days"); // modify is a method (function) that does what it says { similar to strtotime }
} else {
    $myDate->modify("+5 days");
}

echo $myDate->format("l, F j, Y") . "<br>"; // Display it in the format of your choosing:
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.