Hey there! any question in your mind? Ask It Now!.

Popular Categories





Disables dates on my js calendar

0 votes
43 views
asked in Programming by Eathen (1,930 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
answered by nitu (1,680 points)
selected by Eathen
 
Best answer

Hello dear you can use this code :-

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

Related Questions

0 votes
1 answer 9,830 views
+4 votes
1 answer 614 views
+5 votes
1 answer 1,167 views
+8 votes
3 answers 121 views
+6 votes
1 answer 236 views
+6 votes
1 answer 1,636 views
+7 votes
1 answer 566 views
asked in Programming by neha (560 points)
0 votes
1 answer 242 views
0 votes
1 answer 390 views
+1 vote
1 answer 156 views

Not a Member yet?

Ask to Folks Login

My Account
834 Folks are online
68 members and 766 guest online
Your feedback is highly appreciated