Jump to content

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
https://forums.phpfreaks.com/topic/305358-add-3-days-to-date/
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
https://forums.phpfreaks.com/topic/305358-add-3-days-to-date/#findComment-1552704
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.