-1

I would like to create a script where time which you will get depends on the day.

f it's a normal week day it should echo the current date but time < 4pm if the time is >4pm that it should echo +2 day. But if today is Friday and the is >4pm and Saturday/Sunday then it should echo Monday for friday and Saturday and Tuesday for Sunday and so there should be also a countdown like : "Order within....(depends on the minutes until tomorrow 4pm or day with 4pm)"

for ex.

Today is Monday 3pm: The customer have 1 hour to buy to get teh product on Tuesday so the code should echo: "Want it Tuesday, Jan. 28? Order within 00 hrs 57 mins"

Today is Monday 6pm: The customer have now time to buy it until tomorrow 4pm to get it Wednesday so the code should echo: "Want it Wednesday, Jan. 29? Order within 22 hrs 00 mins"

.. .. ..

Today is Friday 3pm: The customer have 1 hour to buy to get teh product on Saturday so the code should echo: "Want it Saturday, $date ? Order within 00 hrs 57 mins"

Today is Friday 5pm: The customer have 1 hour to buy to get teh product on Monday so the code should echo: "Want it Monday, $date ? Order within $timer"

Today is Saturday 3pm/6pm: The customer have now time to buy it until tomorrow 4pm to get it Monday so the code should echo: "Want it Tuesday, $date? Order within $timer(coundown until Monday 4pm)"

Today is Sunday 3pm/6pm: The customer have now time to buy it until tomorrow 4pm to get it Monday so the code should echo: "Want it Tuesday, $date? Order within $timer(coundown until Monday 4pm)"

$time = new DateTime('today 4 PM');

$now = new DateTime('now');

// check if current time is past 6 PM

if ($now > $time) {
    $time = new DateTime('tomorrow 4 PM');
}
$diff = $time->diff($now);    

    $dw = date( "w");
    if ($dw == 6 || $dw == 0) {
        $datetime = new DateTime('today');
        if ($dw == 6) {
            $datetime->modify('+3 day');
        } else {
            $datetime->modify('+2 day');
        }
        echo "Contact us again at: " . $datetime->format('Y-m-d');
    } else {
        //echo "<span>Today is:</span> " . date('<b>l jS \of F Y</b>')."<br/>";

        $datetime = new DateTime('today');
        $datetime->modify('+1 day');


    }



        echo "Delivery: ". $datetime->format('<b>l, d F</b>') . ": <span style ='color:#198504'>Order in: </span> ";
        echo $diff->format("<span style ='color:#198504'>%h hours und %i Minutes.</span>");
    }

What can I change that the script works like I want

Gaven
  • 21
  • 1
  • 6

1 Answers1

0
<?php
//its the time 0-23
$hour = date(" H ");
//its the day of week 1 to 7. "1 is monday."
$weeksday = date(" N ");
$weeksdayname = date(" l ");

echo $weeksdayname.' Time: '.($hour+1);

if($weeksday < 5 || ($weeksday == 5 && ($hour+1) < 16)) {
    echo "<br>Friday before 4 PM. and Weekday.";
    if ($weeksday = 1) { //if its monday
        echo "Contact us on Wednesday."
    }
    else if ($weeksday = 2 && ($hour+1) > 16) { //if its tuesday
        echo "Contact us on Thursday."
    }
    else if ($weeksday = 3 && ($hour+1) >  16) { //if its wednesday
        echo "Contact us on *****."
    }
    else if ($weeksday = 4 && ($hour+1) > 16) { //thursday
        echo "Contact us on *****."
    }
    else if ($weeksday = 5 && ($hour+1) > 16) { //friday
        echo "Contact us on *****."
    }
}
else { //Friday after 4PM till monday 00:00
    echo "<br>Weekend.";
}

?>
  • You can change the echo's however you want. –  Jan 25 '14 at 11:53
  • but whats with the time feature – Gaven Jan 25 '14 at 15:07
  • What do you mean? Can you explain it a bit more clear? –  Jan 25 '14 at 16:15
  • so if the time past 4 pm (limit) it should echo a countdown to +1 day for ex. if it is Monday 5pm that it should echo a countdown Tuesday but is should echo "Want it Wednesday, Jan. 29? Order within $countdown(countdown to Tuesday 4pm(that the time where he can buy it and get it next day)" but if it is 3pm friday than echo Want it Saturday, Feb. 1? Order within $countdown(countdown to Friday 4pm)" and if it is 5pm friday or Saturday Sunday than echo Want it Tuesday, Feb. 4? Order within $countdown(countdown to Monday 4pm)" – Gaven Jan 26 '14 at 19:58