我数据库里面有个字段pubinwebdate是datetime格式,存放YYYY-mm-dd H:i:s 这种格式的时间数据。
我想查询数据段里某个时间段的数据,一直报错,查了很多资料,都尝试了一下,还是不行。
$sql2 = 'SELECT * FROM ' .$ecs->table('getroom'). ' WHERE pubinwebdate BETWEEN '.'2020-11-20 00:00:00'.' AND '.'2020-12-20 00:00:00';
也尝试过用pubinwebdate > and pubinwebdate < 这样的方式查询,也是一直报错,报错内容如下:
MySQL server error report:Array ( [0] => Array ( [message] => MySQL Query Error ) [1] => Array ( [sql] => SELECT * FROM `wofumeishi`.`ecs_getroom` WHERE pubinwebdate BETWEEN 2020-11-20 00:00:00 AND 2020-12-20 00:00:00 ) [2] => Array ( [error] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00:00:00 AND 2020-12-20 00:00:00' at line 1 ) [3] => Array ( [errno] => 1064 ) )
实在没辙了,还望各位大神指点一下,到底错在哪了。