Lynx
Lynx

Reputation: 1482

Disable Monday after 4:00pm on Saturday

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?

My working code:

$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;
        }

Upvotes: 3

Views: 262

Answers (2)

CodeBird
CodeBird

Reputation: 3858

<?php
$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);
}

Just used John Conde code, add the -1 Month, should work. Prints out 2014-01-24, so basically it should disable monday 24 feb in the jscal

Upvotes: 1

John Conde
John Conde

Reputation: 219864

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

See it in action

Upvotes: 1

Related Questions