PHP的if语句来检查当前日期时间是否在2 datetime列之间 [英] php if statement to check if current datetime is between 2 datetime columns
本文介绍了PHP的if语句来检查当前日期时间是否在2 datetime列之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PostQopen和PostQClose是日期时间列。
我需要一个php if语句来检查当前日期时间是否在PostQopen和PostQClose列之间。
PostQopen and PostQClose are datetime columns. I need a php if statement to check if the current datetime is between the PostQopen and PostQClose columns.
$now = date('Y-m-d H:i:s');
if($rows['PostQopen'] >= '$now' && $rows['PostQClose'] < '$now' ){
echo "TRUE";
} else {
echo "FALSE";
};
推荐答案
使用日期时间。
$now = new DateTime("now");
$PostQopen = new DateTime($rows['PostQopen']);
$PostQClose = new DateTime($rows['PostQClose']);
if($PostQopen >= $now && $PostQClose <=$now){
// do ur stuff
}
这篇关于PHP的if语句来检查当前日期时间是否在2 datetime列之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文