MySQL str_to_date string converted to date

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.