【发布时间】:2014-07-04 06:32:37
【问题描述】:
我有以下 MySQL 语法,这给了我一个错误。
我知道你不能直接比较日期变量,所以我使用strtotime 创建一个 Unix 时间戳来比较日期。
你能在 MySQL 查询中使用 PHP strtotime 函数吗?
$result = select * from table where strtotime(Date) >= strtotime($_POST[DateFrom1])
&& strtotime(Date) <= strtotime($_POST[DateTo1])";
【问题讨论】:
-
PHP 不对!不,使用 PHP 无法将 MySQL 表字段从字符串转换为时间。
-
是什么让你觉得不能在mysql中直接比较日期字段?可以,只要列类型是
date或datetime或其他与日期相关的类型。