mysql的str to date_mysql str_to_date字符串转换为日期

mysql内置函数,在mysql里面利用str_to_date()把字符串转换为日期。

示例:分隔符一致,年月日要一致

select str_to_date('2008-4-2 15:3:28','%Y-%m-%d %H:%i:%s');

select str_to_date('2008-08-09 08:9:30', '%Y-%m-%d %h:%i:%s');

对于这个已经理解,但是为何查询字段时使用这种方法查询出来的数据为null????

刚发现的问题,尝试在client上查询,发现可以出现数据,但是在SQLyog上却是null

mysql> SELECT STR_TO_DATE(startDate,'%Y年%m月%d日') FROM caselibrarycommon;

+---------------------------------------+

| STR_TO_DATE(startDate,'%Y年%m月%d日') |

+---------------------------------------+

| 2015-06-16 |

| 2015-06-05 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-07 |

| 2015-06-09 |

| 2015-06-08 |

| 2015-06-10 |

| 2015-06-11 |

| 2015-06-11 |

| 2015-06-11 |

| 2015-06-12 |

mysql的str to date_mysql str_to_date字符串转换为日期_第1张图片

这是什么原因?

mysql> SELECT STR_TO_DATE(startDate,'%Y年%m月%d日') FROM caselibrarycommon

-> WHERE STR_TO_DATE(startDate,'%Y年%m月%d日') BETWEEN STR_TO_DATE('2015年6

'> 月5日','%Y年%m月%d日') AND STR_TO_DATE('2015年6月20日','%Y年%m月%d日');

+---------------------------------------+

| STR_TO_DATE(startDate,'%Y年%m月%d日') |

+---------------------------------------+

| 2015-06-16 |

| 2015-06-05 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-06 |

| 2015-06-07 |

| 2015-06-09 |

| 2015-06-08 |

| 2015-06-10 |

| 2015-06-11 |

| 2015-06-11 |

| 2015-06-11 |

| 2015-06-12 |

| 2015-06-16 |

| 2015-06-16 |

| 2015-06-17 |

| 2015-06-17 |

| 2015-06-17 |

| 2015-06-18 |

+---------------------------------------+

20 rows in set (0.00 sec)

select str_to_date(detectResult.`rcvDetectTime`,'%Y-%m-%d %H:%i:%s') from detectResult where str_to_date(detectResult.`rcvDetectTime`,'%Y-%m-%d %H:%i:%s')>='2010-11-22 14:49:52' and str_to_date(detectResult.`rcvDetectTime`,'%Y-%m-%d %H:%i:%s')<='2010-11-22 15:27:52'

给自己点个赞,么么哒(づ ̄ 3 ̄)づ

你可能感兴趣的:(mysql的str,to,date)