toolman Posted October 14, 2017 Share Posted October 14, 2017 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 More sharing options...
requinix Posted October 14, 2017 Share Posted October 14, 2017 Use date() to determine whether today is a weekday or not, then use strtotime to create a date representing however-many days in the future you want. Link to comment Share on other sites More sharing options...
Gandalf64 Posted October 14, 2017 Share Posted October 14, 2017 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 More sharing options...
toolman Posted October 15, 2017 Author Share Posted October 15, 2017 Thank you Link to comment Share on other sites More sharing options...
cloetensbrecht Posted October 19, 2017 Share Posted October 19, 2017 echo "Order today to receive by " . date("l j F Y", (time() + (86400 * date("N", time()) < 6 ? 5 : 3))); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.