今天就跟大家聊聊有關(guān)使用php怎么對兩個字符串日期的大小進(jìn)行比較,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
具體如下:
$to) { 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)));
最終取得一個日期的 Unix 時間戳$date=1255392000。
很多時候做搜索的時候,搜索的時間不能大于當(dāng)前日期,比較函數(shù)的寫法大致和上面一個函數(shù)相同,具體如下:
function dateBCurrent($date){ //日期是否大于當(dāng)前日期 $currentDate=date("Y-m-d"); //獲取當(dāng)前日期 $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); //當(dāng)前日期的 Unix 時間戳 $dateUnix=mktime(0,0,0,$month,$day,$year); //待比較日期的 Unix 時間戳 if($dateUnix<=$currentUnix){ return true; }else{ return false; } }
看完上述內(nèi)容,你們對使用php怎么對兩個字符串日期的大小進(jìn)行比較有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。