mysql Incorrect datetime value: '2016-02%' for column
1、我有数据表BlogLog:
mysql> select pid,logCreateTime from BlogLog limit 1,5;
+-----+---------------------+
| pid | logCreateTime |
+-----+---------------------+
| 19 | 2015-04-11 18:56:32 |
| 20 | 2016-02-11 19:56:32 |
| 21 | 2016-02-12 19:56:32 |
| 22 | 2016-02-13 19:43:18 |
| 23 | 2016-02-13 20:26:22 |
+-----+---------------------+
2、取出年月:
mysql> select distinct date_format(logCreateTime,'%Y-%m') from BlogLog group by logCreateTime;
+------------------------------------+
| date_format(logCreateTime,'%Y-%m') |
+------------------------------------+
| 2015-04 |
| 2016-02 |
+------------------------------------+
3、再以年月查询数据库:
select pid from BlogLog where user_pid=1 and logCreateTime like '2016-02%';
pid结果能找到,但是有一个warning:
15:56:21,418 WARN SqlExceptionHelper:232 - SQL Warning Code: 1292, SQLState: 22007
15:56:21,419 WARN SqlExceptionHelper:233 - Incorrect datetime value: '2016-02%' for column 'logCreateTime' at row 1
15:56:21,423 WARN SqlExceptionHelper:232 - SQL Warning Code: 1292, SQLState: 22007
15:56:21,424 WARN SqlExceptionHelper:233 - Incorrect datetime value: '2015-04%' for column 'logCreateTime' at row 1
4、问题分析
每次log4j都会打印出来,甚烦,我的mysql版本是5.6.22,
网上有的说是5.6版本时间有所不同,但我不想换数据库版本,
我知道引起警告的原因是我的 '2016-02%'不是时间的标准格式,但我需要以年月对文章归档,不得不如此查询,
我尝试
mysql> select pid from BlogLog where logCreateTime like concat(str_to_date('2016-02', '%Y-%m'), '%');
却Empty set (0.00 sec)
查不出数据
请教大家,有好的方法查询不出警告么?