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 '.
It is recommended to use the 2nd type
Second, date to string
Mysql> Select Date_format (now (), '%Y '); +-------------------------+| Date_format (now (), '%Y ') |+-------------------------+| |+-------------------------+1 row in Set (0.00 sec) Extension:%Y: Year%c: Month%d: Day%h: Hour%i: minutes%s: Seconds mysql> 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 |+----------------------------------------+1 row in Set (0.00 sec)
MySQL Date conversion