Page 1 of 1

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

Posted: Mon Jul 13, 2015 4:37 am
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";
}

?>

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

Posted: Mon Jul 13, 2015 5:51 am
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'));