PHP比较日期时间值 [英] PHP Compare datetime values
本文介绍了PHP比较日期时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的PHP应用程序中,我试图比较日期时间值,如下所示:
In my PHP application I'm trying to compare date time values like the following:
if($datetime_from_db < date('Y-m-d H:i:s'))
{
// then do something
}
两个值的格式相同。我不知道为什么它只比较日期而忽略时间。日期和时间值对我来说都很重要,但是我不知道如何使它起作用。
Both values are in the same format. What I can't figure out is why it only compares the date and ignores the time. Both the date and the time values are important for me but I don't know how to make it work.
推荐答案
字符串,例如 2011-02-14 15:46:00
与另一个字符串实际上并没有比较 dates ,它会根据字符串解析数字规则,比较两个字符串。您需要比较实际的数字时间戳:
Comparing a string like "2011-02-14 15:46:00"
to another string doesn't actually compare dates, it compares two strings according string parsing numeric rules. You will need to compare actual numeric timestamps:
strtotime($datetime_from_db) < time()
这篇关于PHP比较日期时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文