PHP implements a method of comparing two string date sizes, PHP string
The example in this article describes how PHP implements a comparison of two string date sizes. Share to everyone for your reference. Specific as follows:
<?phpfunction datebdate ($date 1, $date 2) {//date 1 is greater than date 2 $month 1 = date ("M", Strtotime ($date 1)), $month 2 = Date ("M", STRT Otime ($date 2)); $day 1 = date ("D", Strtotime ($date 1)); $day 2 = date ("D", Strtotime ($date 2)); $year 1 = date ("Y", Strtotime ($date 1)); $year 2 = Date ("Y", Strtotime ($date 2)); $from = mktime (0, 0, 0, $month 1, $day 1, $year 1); $to = mktime (0, 0, 0, $month 2, $day 2, $year 2); if ($from > $to) {return true;} else {return false;}} ?> $date 1 = "2009-10-13"; $date = mktime (0, 0, 0, date ("M", Strtotime ($date 1)), date ("D", Strtotime ($date 1)), date ("Y", s Trtotime ($date 1)));
Finally get a date for the Unix timestamp $date=1255392000.
Many times when searching, the search time can not be greater than the current date, the comparison function is roughly the same as the above one function, as follows:
function Datebcurrent ($date) {//date is greater than the current date $currentDate =date ("y-m-d");//Gets 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 for the current date $dateUnix =mktime (0,0,0, $month, $day, $year); The Unix timestamp for the date to compare if ($dateUnix <= $currentUnix) {return true;} else{return false;}}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/998547.html www.bkjia.com true http://www.bkjia.com/PHPjc/998547.html techarticle PHP implementation to compare two string date size method, PHP String This article describes the PHP implementation of a comparison of two string date size method. Share to everyone for your reference. Specific as ...