Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较mysql php的日期_Php_Mysql_Comparison - Fatal编程技术网

比较mysql php的日期

比较mysql php的日期,php,mysql,comparison,Php,Mysql,Comparison,我正在尝试创建日历视图。我需要检查mysql查询中的$currentDateTime是否介于startdate和enddate之间 我尝试了这个查询,基于 从hirings中选择id、开始日期、结束日期 其中startdate将查询更改为startdate>=而不是=“$currentDateTime”和enddate确保使用默认的日期时间格式YYYY-MM-DD HH:MM:ss SELECT id, startdate, enddate FROM hirings WHERE '$curren

我正在尝试创建日历视图。我需要检查mysql查询中的
$currentDateTime
是否介于
startdate
enddate
之间

我尝试了这个查询,基于

从hirings中选择id、开始日期、结束日期

其中startdate将查询更改为startdate>=而不是=“$currentDateTime”和enddate确保使用默认的日期时间格式
YYYY-MM-DD HH:MM:ss

SELECT id, startdate, enddate
FROM hirings
WHERE '$currentDateTime' between startdate AND enddate
或者,如果要使用当前SQL时间,则查询甚至不需要参数

SELECT id, startdate, enddate
FROM hirings
WHERE NOW() between startdate AND enddate
试试这个:

SELECT hr.id, hr.startdate, hr.enddate 
FROM hirings hr
WHERE STR_TO_DATE('$currentDateTime', '%d-%m-%Y %H:%i:%s')
between hr.startdate AND hr.enddate;

您的PHP日期时间是什么格式的?使用
YYYY-MM-DD HH:MM:ss
startdate=
数据库中startdate和enddate的数据类型是什么?以及它们是如何存储的?我使用了你的sql,它工作了!谢谢不过我还是保留了相同的格式,它仍然有效…你能详细说明你的答案吗?通常不鼓励只使用代码的答案。
SELECT hr.id, hr.startdate, hr.enddate 
FROM hirings hr
WHERE STR_TO_DATE('$currentDateTime', '%d-%m-%Y %H:%i:%s')
between hr.startdate AND hr.enddate;