PHP:日期大于当前日期

编程入门 行业动态 更新时间:2024-10-25 08:28:19
本文介绍了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:日期大于当前日期

本文发布于:2023-10-31 07:18:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!