There is such A requirement that the specified date is July 22, December 12. Before July 15, December 12, I want to execute event A, and then I want to execute event B. How can I determine whether today is before or after July 15, December 12?
The procedure is as follows:
<? Php $ year = 2010; $ month = 12; // month $ day = 12; // day $ timeoffset = 8; // list of time difference between the GMT and GMT ($ thisyear, $ thismonth, $ thisday) = explode ('-', date ('Y-n-J', time () + $ timeoffset x 3600 )); if ($ thismonth> $ month) | ($ thismonth =$ month & $ thisday> $ day) | $ thisyear> $ year) {echo 'already exists';} elseif ($ thismonth = $ month & $ thisday = $ day & $ thisyear = $ year) {echo 'is today';} else {echo 'hasn't arrived yet';}?>
The following code is annotated:
// Another variable you need to know is the year, but you mean the year. $ Timestamp = time (); $ dateYear = date ('y', $ timestamp); // the current year, which can be compared based on the current needs, but may be used sometimes, for example, your record is not the $ dateMonth = date ('n', $ timestamp) to be processed in the current year; // The number of the current month, no leading zero $ dateDay = date ('J ', $ timestamp); // The day of the month. If there is no leading zero, then compare. For example, the date you want to compare is 2007 $ eventDate = '2017-01 1 '; $ eventDateArr = explode ('-', $ eventDate); $ eventYear = intval ($ eventDateArr [0]); $ eventMonth = intval ($ eventDateArr [1]); $ eventDay = intval ($ eventDateArr [2]); // The above is the split of year, month, and day, which can be adjusted according to the actual situation. If you can get it directly, you do not need to take it like this. // After comparison, compare the year if ($ dateYear = $ eventYear) {// if ($ dateMonth = $ eventMonth) in the same year first) {// same month if ($ dateDay ==$ eventDay) {// the same day, that is, the current date is the date triggered by the event} elseif ($ dateDay> $ eventDay) {// The event has expired} else {// The Event trigger date has not reached} else {// before or after, you need to determine in detail which month can be compared here?} else {// before or after, you need to determine in detail which year can be compared here} // In fact, this comparison is the simplest logic judgment. If you record the unix timestamp when the time trigger date is recorded, the timestamp can be compared directly here, but it needs to be processed, because the timestamp is accurate to the second // or the date you recorded and the next day are directly converted to the unix timestamp, the time and second are both 0 and current Compare the timestamp and analyze the details. Use the function to check strtotime () in the manual. There are many time-related function parameters, but you will be familiar with it several times.