PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5
The format of aDATE value is'. According to standard SQL, no other format is permitted. You should use this format inYYYY-MM-DD'UPDATE expressions and in theWHERE clause ofSELECT statements. For example:
SELECT * FROM t1 WHERE date >= '2003-05-05'; As a convenience, MySQL automatically converts a date to a number if the date is used in numeric context and vice versa. MySQL also permits a“relaxed” string format when updating and in aWHERE clause that compares a date to aDATE,DATETIME, orTIMESTAMP column.“Relaxed” format means that any punctuation character may be used as the separator between parts. For example,'2004-08-15' and'2004#08#15' are equivalent. MySQL can also convert a string containing no separators (such as'20040815'), provided it makes sense as a date.
When you compare aDATE,TIME,DATETIME, orTIMESTAMP to a constant string with the<,<=,=,>=,>, orBETWEEN operators, MySQL normally converts the string to an internal long integer for faster comparison (and also for a bit more“relaxed” string checking). However, this conversion is subject to the following exceptions:
For those exceptions, the comparison is done by converting the objects to strings and performing a string comparison.
To be on the safe side, assume that strings are compared as strings and use the appropriate string functions if you want to compare a temporal value to a string.
The special“zero” date'0000-00-00' can be stored and retrieved as'0000-00-00'. When a'0000-00-00' date is used through Connector/ODBC, it is automatically converted toNULL because ODBC cannot handle that kind of date.
Because MySQL performs the conversions just described, the following statements work (assume thatidate is aDATE column):
INSERT INTO t1 (idate) VALUES (19970505);INSERT INTO t1 (idate) VALUES ('19970505');INSERT INTO t1 (idate) VALUES ('97-05-05');INSERT INTO t1 (idate) VALUES ('1997.05.05');INSERT INTO t1 (idate) VALUES ('1997 05 05');INSERT INTO t1 (idate) VALUES ('0000-00-00');SELECT idate FROM t1 WHERE idate >= '1997-05-05';SELECT idate FROM t1 WHERE idate >= 19970505;SELECT MOD(idate,100) FROM t1 WHERE idate >= 19970505;SELECT idate FROM t1 WHERE idate >= '19970505';However, the following statement does not work:
SELECT idate FROM t1 WHERE STRCMP(idate,'20030505')=0;STRCMP() is a string function, so it convertsidate to a string in' format and performs a string comparison. It does not convertYYYY-MM-DD''20030505' to the date'2003-05-05' and perform a date comparison.
If you enable theALLOW_INVALID_DATES SQL mode, MySQL permits you to store dates that are given only limited checking: MySQL requires only that the day is in the range from 1 to 31 and the month is in the range from 1 to 12. This makes MySQL very convenient for Web applications where you obtain year, month, and day in three different fields and you want to store exactly what the user inserted (without date validation).
MySQL permits you to store dates where the day or month and day are zero. This is convenient if you want to store a birthdate in aDATE column and you know only part of the date. To disallow zero month or day parts in dates, enable theNO_ZERO_IN_DATE mode.
MySQL permits you to store a“zero” value of'0000-00-00' as a“dummy date.” This is in some cases more convenient than usingNULL values. If a date to be stored in aDATE column cannot be converted to any reasonable value, MySQL stores'0000-00-00'. To disallow'0000-00-00', enable theNO_ZERO_DATE mode.
To have MySQL check all dates and accept only legal dates (unless overridden byIGNORE), set thesql_mode system variable to"NO_ZERO_IN_DATE,NO_ZERO_DATE".
PDF (A4) - 35.2Mb
Man Pages (TGZ) - 256.4Kb
Man Pages (Zip) - 361.2Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
MySQL Globalization
MySQL Information Schema
MySQL Installation Guide
MySQL and Linux/Unix
MySQL and macOS
MySQL Partitioning
MySQL Performance Schema
MySQL Replication
Using the MySQL Yum Repository
MySQL Restrictions and Limitations
Security in MySQL
MySQL and Solaris
Building MySQL from Source
Starting and Stopping MySQL
MySQL Tutorial
MySQL and Windows
MySQL NDB Cluster 7.5