Oracle 5.0 Reference Manual page 2988

Table of Contents

Advertisement

• When you compare a DATE, TIME, DATETIME, or
• When you use any comparison method other than those just listed, such as
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'
ODBC cannot handle that kind of date.
Because MySQL performs the conversions just described, the following statements work (assume that
is a
idate
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;
[898]
STRCMP()
performs a string comparison. It does not convert
perform a date comparison.
If you enable the
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 a
or day parts in dates, enable the
MySQL permits you to store a "zero" value of
cases more convenient than using
converted to any reasonable value, MySQL stores '0000-00-00'. To disallow '0000-00-00',
enable the
NO_ZERO_DATE
To have MySQL check all dates and accept only legal dates (unless overridden by IGNORE), set the
[495]
sql_mode
Date handling in MySQL 5.0.1 and earlier works like MySQL 5.0.2 with the
ALLOW_INVALID_DATES
C.5.5.3. Problems with
The concept of the
think that
NULL
following statements are completely different:
'0000-00-00'
date is used through Connector/ODBC, it is automatically converted to
column):
DATE
is a string function, so it converts
ALLOW_INVALID_DATES
DATE
NO_ZERO_IN_DATE
[538]
SQL mode.
system variable to "NO_ZERO_IN_DATE,NO_ZERO_DATE".
[535]
SQL mode enabled.
Values
NULL
value is a common source of confusion for newcomers to SQL, who often
NULL
is the same thing as an empty string ''. This is not the case. For example, the
Query-Related Issues
TIMESTAMP
can be stored and retrieved as
idate
'20030505'
[535]
SQL mode, MySQL permits you to store dates that
column and you know only part of the date. To disallow zero month
[538]
'0000-00-00'
values. If a date to be stored in a
NULL
2968
column to an expression
IN
'0000-00-00'.
to a string in
'YYYY-MM-DD'
to the date
'2003-05-05'
SQL mode.
as a "dummy date." This is in some
DATE
or
[898].
STRCMP()
When a
because
NULL
format and
and
column cannot be

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents