0 votes
in Programming by (1.9k points)

I have built a small function that disables dates on my js calendar (which would explain the -1 month) after 4 pm the following date will be disabled. The business I built this for is opened Monday - Saturday, so a problem arises when it's Saturday it will disable Sunday but actually it needs to disable Monday (their next working day). How can I edit my code to allow Monday to be disabled if it's after 4:00PM on Saturday while retaining the other days?

$datetime = new DateTime();

$deadline = new DateTime("today 4:00PM");

$today = new Datetime('today');

$todays = $today->format('Y-m-d');

$db_date = strtotime($todays);

$todaydisable = date('Y-m-d', strtotime("-1 month", $db_date));

if($datetime > $deadline){
    $tomorrow = Date("Y,m,d", strtotime("+1 day -1 month "));

} else {
    $tomorrow = NULL;

Tried the code below doesn't work either It will disable the next day but does not disable Monday if it's after 4 on Saturday

 $now      = new DateTime("-1 month");
        $deadline = clone $now;
        $deadline->setTime(4, 00);
        if ($now > $deadline) {
            $now->modify('+1 day');
            $when = ('-1 month Saturday' === $now->format('l')) ? '-1 month Next Monday' : '-1 month Tomorrow';
            $tomorrow = new DateTime($when);
            $tomorrowFormat = $tomorrow->format('Y,m,d');
        } else {
            $tomorrowFormat = NULL;

1 Answer

+1 vote
by (1.7k points)
selected by
Best answer

Hello dear you can use this code :-

$now= new DateTime();
$deadline = clone $now;
$deadline->setTime(16, 00);
if ($now > $deadline) {
    //$now->modify('+1 day');
$when = ('Saturday' === $now->format('l'))
? '-1 Month Next Monday' : '-1 Month Tomorrow';
 $tomorrow = new DateTime($when);

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated