我正在尝试制作日历视图。我需要检查mysql查询中$currentDateTimestartdate之间是否是enddate

我已经根据Compare dates in MySQL 尝试过此查询

SELECT id, startdate, enddate FROM hirings
WHERE startdate <= '$currentDateTime'
AND enddate <= '$currentDateTime'


其中$ currentDateTime的格式为dd-mm-yyyy hh:mm

但是它似乎不起作用,我一直返回0 rows

任何帮助,将不胜感激 :)

最佳答案

确保使用默认的日期时间格式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

关于php - 比较日期mysql php,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24417205/

10-13 07:32
查看更多