简体   繁体   English

如何在php中比较日期?

[英]How to Compare Dates in php?

i need code to compare date in php 我需要代码来比较PHP中的日期

  1. Input date should be a valid date 输入日期应为有效日期
  2. input date should not be less than the current date. 输入日期不能小于当前日期。
  3. i need to give time zones EST,PST,etc.. 我需要给时区EST,PST等。
  4. We need to make the time to GMT and compare with Current Time. 我们需要花时间到格林尼治标准时间,并与当前时间进行比较。

can anyone help on this. 谁能帮上忙。 Thanks Ramakrishnan.p 谢谢Ramakrishnan.p

This is a late answer. 这是一个较晚的答案。 since there is no exact answer to the question here, I'm providing this solution here. 由于此处没有确切的问题答案,因此我在此处提供此解决方案。

You can do it in this way 你可以这样

$date1 = strtotime("2007-02-20"); // your input
$date2 = strtotime("today"); //today
if($date1 < $date2) {
    echo " input date is in the past";
}

strtotime converts the string in to the unix timestamp integer. strtotime将字符串转换为unix时间戳整数。

Take a look at the maketime() function. 看一下maketime()函数。 Then compare the resulting UNIX timestamps. 然后比较所得的UNIX时间戳。

查看Zend Framework的日期: http ://framework.zend.com/manual/en/zend.date.overview.html您只需要框架中的Date.php文件和Date / Locale文件夹即可使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM