The examples in this article describe a PHP implementation that compares two string date size methods. Share to everyone for your reference. as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 |
<?php function Datebdate ($date 1, $date 2) {//date 1 is greater than date 2 $month 1 = date ("M", Strtotime ($date 1)); $month 2 = Date ("M", St Rtotime ($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", Strtotime ($date 1)); |
A Unix timestamp $date=1255392000 that eventually gets a date.
Many times when doing a search, the search time can not be greater than the current date, the comparison function is roughly the same as the above function, specifically as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19-20 |
function Datebcurrent ($date) {//date is greater than the current date $currentDate =date ("y-m-d");//Get 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); The current date of the Unix timestamp $dateUnix =mktime (0,0,0, $month, $day, $year); The Unix timestamp if ($dateUnix <= $currentUnix) {return True when the date is to be compared;} else{return false;} |
I hope this article will help you with your PHP program design.