One, string to date
Here's how to convert a string into a date in MySQL:
Background: RQ field information is: 20100901
1, do not need to convert:
SELECT * from Tairlist_day WHERE rq> ' 2010-07-31 ' and rq< ' 2010-09-01 '
2. Use: Date_format
SELECT * from Tairlist_day WHERE date_format (RQ, '%y-%m-%d ') > ' 2010-08-01 ' and Date_format (RQ, '%y-%m-%d ') < ' 2010-0 8-03 '
The 1th one to be in a "loose" syntax is allowed: Use any punctuation as a delimiter in the date part and time part, such as:
A number in YYYYMMDD or YYMMDD format, as long as the number looks like a date. For example, 19830905 and 830905 are interpreted as ' 1983-09-05 '.
Select Date_format (now (), '%y-%c-%d%h:%i:%s ');
+----------------------------------------+| Date_format (now (), '%y-%c-%d%h:%i:%s ') |+----------------------------------------+| 2009-8-07 06:59:40 in Set (0.00 sec)
Select Date_format (now (), '%Y ');
+-------------------------+| Date_format (now (), '%Y ') |+-------------------------+| In Set (0.00 sec) Extension:%Y: Year %C: Month %D: Day h: Hour %i: minutes %s: Seconds
mysql-Date Conversion