我有以下 MySQL 语法,这给了我一个错误。
我知道你不能直接比较日期变量,所以我使用strtotime
创建 Unix 时间戳来比较日期。
你可以使用PHP吗strtotime
MySQL 查询中的函数?
$result = select * from table where strtotime(Date) >= strtotime($_POST[DateFrom1])
&& strtotime(Date) <= strtotime($_POST[DateTo1])";
你的代码必须是这样的:
$result = "select * from table
where unix_timestamp(Date) >= unix_timestamp(".$_POST[DateFrom1].")
&& unix_timestamp(Date) <= unix_timestamp(".$_POST[DateTo1].")";
要在 mysql 中将日期转换为时间戳,有函数unix_timestamp
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)