MySQL built-in function that uses str_to_date () to convert a string to a date inside MySQL.
Example: The delimiter is the same, month and day
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 ');
For this already understood, but why query fields when using this method to query out the data is null????
Just found the problem, try to query on the client, found that the data can appear, but on the SQLyog is null
Mysql> SELECT str_to_date (startdate, '%y year%m month%d day ') from Caselibrarycommon;
+---------------------------------------+
| Str_to_date (StartDate, '%y%m month%d day ') |
+---------------------------------------+
| 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 |
What is the reason for this?
Mysql> SELECT str_to_date (startdate, '%y year%m month%d day ') from Caselibrarycommon
--WHERE Str_to_date (StartDate, '%y%m month%d day ') between Str_to_date (' 2015 6
' > Month 5th ', '%y year%m Month%d ') and Str_to_date (' June 20, 2015 ', '%y year%m month%d ');
+---------------------------------------+
| Str_to_date (StartDate, '%y%m month%d day ') |
+---------------------------------------+
| 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 |
+---------------------------------------+
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 '
Give yourself some praise, づ ̄3 ̄ (old)
MySQL str_to_date string converted to date