mysql中datetime列如何做筛选?
PHP中文网
PHP中文网 2017-04-17 16:31:29
0
2
451

1,数据库中有个数据的创建时间的列 F1,类型是 datetime 类型
2,现在准备做个根据给定时间来筛选数据的功能
3,现在的SQL代码如下:

select * from TABLE where F1 > '2017-01-01 12:23:33'

上面的 > 可以是 < 或者 <=,重点是没用 between and,根据观察发现这么去筛的时候出来的数据有可能不太对。

4,个人猜猜:由于最终转换成字符串的形式比较,所以感觉像是在做字符串比较而非时间比较导致数据不对。

5,问题:想问下大家有什么方法没用可以使出来的数据是正确的,说把列改类型是不可能了,只能从SQL语句上想办法了

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
PHPzhong

There is no problem in comparing datetime like this. Even if it is converted into characters, the comparison effect is the same. Why is your data wrong? You need to find other reasons

迷茫

The solution is to use unix_timestamp to convert it. In the end, it will be no problem to use integer form for comparison.

Excuse me, why can’t string comparison be used directly?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!