This article mainly introduces how to compare the date size of two strings in php, involving related skills in php date operations, for more information about how to compare the date and size of two strings in php, see the following example. Share it with you for your reference. The details are as follows:
<? Phpfunction dateBDate ($ date1, $ date2) {// whether date 1 is greater than date 2 $ month1 = date ("m", strtotime ($ date1 )); $ mon2nd = date ("m", strtotime ($ date2); $ day1 = date ("d", strtotime ($ date1 )); $ day2 = date ("d", strtotime ($ date2); $ year1 = date ("Y", strtotime ($ date1 )); $ year2 = date ("Y", strtotime ($ date2); $ from = mktime (0, 0, 0, $ month1, $ day1, $ year1 ); $ to = mktime (0, 0, 0, $ mon2, $ day2, $ year2); if ($ from> $ ){ Return true;} else {return false; }}?> $ Date1 = "2009-10-13"; $ date = mktime (0, 0, 0, date ("m", strtotime ($ date1), date ("d ", strtotime ($ date1), date ("Y", strtotime ($ date1 )));
Finally, get the Unix timestamp $ date = 1255392000 for a date.
In most cases, the search time cannot be greater than the current date. The comparison function is written in the same way as the previous function, as shown below:
Function dateBCurrent ($ date) {// whether the date is greater than the current date $ currentDate = date ("Y-m-d "); // Obtain the current date $ cYear = date ("Y", strtotime ($ currentDate); $ cMonth = date ("m", strtotime ($ currentDate )); $ cDay = date ("d", strtotime ($ currentDate); $ year = date ("Y", strtotime ($ date )); $ month = date ("m", strtotime ($ date); $ day = date ("d", strtotime ($ date); $ currentUnix = mktime (0, 0, 0, $ cMonth, $ cDay, $ cYear); // Unix timestamp of the current date $ dateUnix = mktime (, 0, $ month, $ day, $ year ); // Unix timestamp of the date to be compared if ($ dateUnix <= $ currentUnix) {return true;} else {return false ;}}
I hope this article will help you with php programming.