十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
今天就跟大家聊聊有关使用php怎么对两个字符串日期的大小进行比较,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
具体如下:
$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。
很多时候做搜索的时候,搜索的时间不能大于当前日期,比较函数的写法大致和上面一个函数相同,具体如下:
function dateBCurrent($date){ //日期是否大于当前日期 $currentDate=date("Y-m-d"); //获取当前日期 $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 时间戳 $dateUnix=mktime(0,0,0,$month,$day,$year); //待比较日期的 Unix 时间戳 if($dateUnix<=$currentUnix){ return true; }else{ return false; } }
看完上述内容,你们对使用php怎么对两个字符串日期的大小进行比较有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。