The date value is in the format ' YYYY-MM-DD '. According to standard SQL, no other format is allowed. You should use this format in the update expression and in the WHERE clause of the SELECT statement. For example:
MySQL> SELECT * FROM tbl_name WHERE date >= '2003-05-05';
For convenience, if the date is used in a numerical environment, MySQL automatically converts the date to a numeric value (and vice versa). It also has considerable intelligence to allow a "loose" string form ("loose form") to be used as a separator between parts, either at update time or in a WHERE clause that compares dates with timestamp, date, or datetime columns. For example, ' 2004-08-15 ' and ' 2004#08#15 ' are equivalent. MySQL can also convert strings that do not contain any delimiters (such as ' 20040815 '), and the precursor is the date it must be meaningful.
When comparing date, time, DateTime, or timestamp with a constant string using the <, <=, =, >=, >, or between operator, MySQL usually converts the string to an inner-ministerial integer. For a quick comparison (and a slightly "loose" string check). However, the conversion has the following exceptions:
When comparing two columns
When comparing a date, time, datetime, or timestamp column to an expression
When using other comparison methods, such as in or strcmp ().
For these exceptions, the object is converted to a string and a string comparison is performed, using this method for comparison.
To keep it safe, suppose you compare strings by string, and if you intend to compare temporary values and strings, use the appropriate string function.
For special date ' 0000-00-00 ', can be saved and retrieved in ' 0000-00-00 ' form. When you use the ' 0000-00-00 ' date in Myodbc, the date is automatically converted to null for MYODBC 2.50.12 or later, because ODBC cannot handle such dates.
Since MySQL is able to perform the transformations described earlier, the following statements work correctly:
mysql> INSERT INTO tbl_name (idate) VALUES (19970505);
mysql> INSERT INTO tbl_name (idate) VALUES ('19970505');
mysql> INSERT INTO tbl_name (idate) VALUES ('97-05-05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997.05.05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997 05 05');
mysql> INSERT INTO tbl_name (idate) VALUES ('0000-00-00');
mysql> SELECT idate FROM tbl_name WHERE idate >= '1997-05-05';
mysql> SELECT idate FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT MOD(idate,100) FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT idate FROM tbl_name WHERE idate >= '19970505';