PHP比较两个日期和时间 [英] PHP Compare two date and time
本文介绍了PHP比较两个日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个日期A,B和C。
I have three dates A, B and C.
A = 2013-08-10 10:00
B = 2013-08-10 12:00
C = 2013-08-10 10:22
我想做的是检查C是否在A和B内,如果它返回true。有人知道如何执行此操作吗?
What I am trying to do is check if C is inside A and B, if it is return true. Anyone have any idea of how to do this?
我没有运气尝试过
if ($time >= $date_start && $time <= $date_end)
{
echo "is between\n";
} else {
echo 'no';
}
推荐答案
您可以将它们转换为UNIX
You can convert them to UNIX timestamp to compare.
$A = strtotime($A); //gives value in Unix Timestamp (seconds since 1970)
$B = strtotime($B);
$C = strtotime($C);
if ((($C < $A) && ($C > $B)) || (($C > $A) && ($C < $B)) ){
echo "Yes '$C' is between '$A' and '$B'";
}
这篇关于PHP比较两个日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文