vendredi 5 octobre 2018

php datetime multiple comparisons not working as expected but work individually?

I'm having issues with my if statement in that both conditions give the expected result individually but when combined so that when both are true the statement breaks.

The idea is to calculate the start date before Christmas so I can show a message about this. My logic was that by ensuring the start date is after October 1st and the end date before December 24th this message will always appear at the correct time give our start and end date schedule.

My code so far is below, there is also a dump below each variable .

foreach ( $events as $event ) {
    $start  =   date("d-m-Y", strtotime($event->EventStartDate));
    // string(10) "26-10-2018"
    $end    =   date("d-m-Y", strtotime($event->EventEndDate));
    // string(10) "20-12-2018"
    echo '<div id="prod-dates">';
    echo '<p>Order&nbsp;before ' . $start . '</p>';
    echo '<p>Estimated&nbsp;Delivery ' . $end . '</p>';
    echo '</div>';
    //
    //EVERYTHING IS FINE UNTIL HERE...
    //
    $this_christmas   =   date('Y-12-24');
    // string(10) "2018-12-24"
    $startx  =   date("Y-m-d", strtotime($event->EventStartDate));
    // string(10) "2018-10-26" 
    $endx    =   date("Y-m-d", strtotime($event->EventEndDate));
    // string(10) "2018-12-20"
    $note_start       =   date('Y-11-01');
    // string(10) "2018-11-01
    if ( $startx >= $note_start || $endx <= $this_christmas ) {
        echo 'This is your last deadline for <span>Christmas&nbsp;Delivery</span>';
    }
}

Any help appreciated.

Thanks

Aucun commentaire:

Enregistrer un commentaire