PHP:日期大于当前日期 [英] PHP: Date larger than current date

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

问题描述

我有这个代码:

$curdate = '22-02-2011';

$mydate = '10-10-2011';                     

if($curdate > $mydate)
{
    echo '<span class="status expired">Expired</span>';
}

这将回覆过期但不应该因为$ mydate是在将来,因此比$ curdate小,但PHP正在查看前两个数字22和10而不是整个字符串。如何解决这个问题?

This would echo expired BUT shouldn't because $mydate is in the future and therefore smaller than the $curdate but PHP is looking at JUST the first two numbers 22 and 10 instead of the whole string. How can I fix this?

谢谢

推荐答案

两个时间戳首先,然后比较两个转换的值:

Try converting them both to timestamps first, and then compare two converted value:

$curdate=strtotime('22-02-2011');
$mydate=strtotime('10-10-2011');

if($curdate > $mydate)
{
    echo '<span class="status expired">Expired</span>';
}

将它们转换为1970年1月1日以来的秒数,所以你的比较应该有效。

This converts them to the number of seconds since January 1, 1970, so your comparison should work.

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

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