php日期比较 [英] php date compare

查看:103
本文介绍了php日期比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的php。我有小问题来比较php中的日期。



我有4个日期名为date1,date2,start_date和end_date,格式为 yyyy-mm- dd



我需要这样的功能:

 code> if((date1> = start_date)&(date2 <= end_date)){

}

请帮我解决这个问题。

解决方案

,这可以很容易地由DateTime和DateDiff类处理。如果没有,那就更难了,但请查看在线PHP手册中DateDiff的用户贡献部分。


I am newbe to php. I have small problem to compare dates in php.

I have 4 dates named date1, date2, start_date and end_date in the format yyyy-mm-dd.

i need the functionality like this:

if((date1>=start_date) && (date2<=end_date)){

} 

please help me to solve this.

解决方案

If you have PHP 5.3, this is easily handled by the DateTime and DateDiff classes. If you have not, it is much harder, but look at the 'user contributed' section on DateDiff in the online PHP manual.

这篇关于php日期比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆