简体   繁体   中英

Date: get the next monday or tuesday from a date

I want to compare two dates, the system date against the date of a record, if the system date is a Thursday and the record date is a Monday, print a blinking <td> . I used 'next Mon', but it does not work

@elseif(date('D') == 'Thu' AND date('D', strtotime($crq->date)) == 'next Mon')
     <td style="background-color: black;color: white"><blink>{{ $crq->date }}<i class="fa fa-exclamation "></i></blink></td>

date() will not output "next Mon", it might print "Mon" if the day is in fact on a Monday, but it will not print "next" (this is using the D format in date() ).

You should instead check if the date is the same. You can do that by checking if the dates are exactly the same from the value in your $crq-date and strtotime("next Monday") , which is the timestamp for the next Monday.

date('Y-m-d', strtotime($crq->date)) == date("Y-m-d", strtotime("next Monday"))

Here's a live demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM