Adding 1 - 2 days, based on current day - odd issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Adding 1 - 2 days, based on current day - odd issues

Post by simonmlewis »

I'm trying to build a little page that comes after someone orders a product.
So this is based on 1-2 days delivery. If they order it by 13:00 on say, a Friday, then it won't be delivered on the Sat or Sun, so will be on a Monday.

I'm sure I can work all this out, but it's doing something weird that I cannot spot.

It should be echoing Saturday I think. Adding 1 day to 17 July. But itstead, it is showing Thursday.
It doesn't matter if I make 17, 18 or 19 or 12, it still shows Thursday.

I just don't see why.

Code: Select all

<?php
//$todaydate = date('Y-m-d');
$todaydate = "2015-07-17";
$orderedon=strftime("%A",strtotime("$todaydate"));
// $todayhour = date('H');
$todayhour = "13";
$day=strftime("%A",time());

echo "</div><div class='cat_head'>Ordered at $todayhour:00 on $orderedon</div><div class='mainbodybox'><br/>";

if ($todayhour <= "13")
{
// add two days to current day

//$onedays = date('Y-m-d', strtotime("+1 days"));
$onedays = date('$todaydate', strtotime("+1 days"));
$onedays=strftime("%A",strtotime("$onedays"));
echo "$onedays";
}

?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Adding 1 - 2 days, based on current day - odd issues

Post by Celauran »

Single quotes around $todaydate means it's not being evaluated but rather passed in as a string. You generally shouldn't be putting quotes around variables. More importantly, the first argument to date() is the pattern, not the time. This works fine:

Code: Select all

echo strftime('%A', strtotime('tomorrow'));
Post Reply