Oracle 5.0 Reference Manual page 859

Table of Contents

Advertisement

• Conversion of values from one temporal type to another occurs according to the rules in
Section 11.1.5.7, "Conversion Between Date and Time
• MySQL automatically converts a date or time value to a number if the value is used in a numeric
context and vice versa.
• By default, when MySQL encounters a value for a date or time type that is out of range or otherwise
illegal for the type, it converts the value to the "zero" value for that type. The exception is that out-of-
range
TIME
• Starting from MySQL 5.0.2, by setting the SQL mode to the appropriate value, you can specify
more exactly what kind of dates you want MySQL to support. (See
Modes".) You can get MySQL to accept certain dates, such as '2009-11-31', by enabling the
ALLOW_INVALID_DATES
MySQL.) This is useful when you want to store a "possibly wrong" value which the user has specified
(for example, in a web form) in the database for future processing. Under this mode, MySQL verifies
only that the month is in the range from 1 to 12 and that the day is in the range from 1 to 31.
• MySQL permits you to store dates where the day or month and day are zero in a
column. This is extremely useful for applications that need to store birthdates for which you may not
know the exact date. In this case, you simply store the date as
If you store dates such as these, you should not expect to get correct results for functions such as
DATE_SUB()
day parts in dates, enable the
• MySQL permits you to store a "zero" value of
cases more convenient than using
'0000-00-00', enable the
• "Zero" date or time values used through Connector/ODBC are converted automatically to
because ODBC cannot handle such values.
The following table shows the format of the "zero" value for each type. The "zero" values are special,
but you can store or refer to them explicitly using the values shown in the table. You can also do this
using the values
DATETIME, and TIMESTAMP), use of these values produces warnings if the
mode is enabled.
Data Type
DATE
TIME
DATETIME
TIMESTAMP
YEAR
11.1.5.1. The DATE, DATETIME, and
The DATE, DATETIME, and
how they are similar, and how they differ. MySQL recognizes DATE, DATETIME, and
values in several formats, described in
DATETIME
guarantee.
The
type is used for values with a date part but no time part. MySQL retrieves and displays
DATE
values in
'YYYY-MM-DD'
The
DATETIME
and displays
'1000-01-01 00:00:00'
values are clipped to the appropriate endpoint of the
[535]
[922]
or
DATE_ADD()
NO_ZERO_IN_DATE
NO_ZERO_DATE
or 0, which are easier to write. For temporal types that include a date part (DATE,
'0'
TIMESTAMP
range descriptions, "supported" means that although earlier values might work, there is no
format. The supported range is
type is used for values that contain both date and time parts. MySQL retrieves
values in
DATETIME
to
'9999-12-31
Date and Time Types
SQL mode. (Before 5.0.2, this mode was the default behavior for
[919]
that require complete dates. To disallow zero month or
[538]
'0000-00-00'
values, and uses less data and index space. To disallow
NULL
[538]
SQL mode.
"Zero" Value
'0000-00-00'
'00:00:00'
'0000-00-00 00:00:00'
'0000-00-00 00:00:00'
0000
Types
TIMESTAMP
types are related. This section describes their characteristics,
Section 9.1.3, "Date and Time
'YYYY-MM-DD HH:MM:SS'
23:59:59'.
839
Types".
range.
TIME
Section 5.1.7, "Server SQL
'2009-00-00'
SQL mode.
as a "dummy date." This is in some
NO_ZERO_DATE
Literals". For the
to '9999-12-31'.
'1000-01-01'
format. The supported range is
or
DATE
DATETIME
or '2009-01-00'.
NULL
[538]
SQL
TIMESTAMP
and
DATE
DATE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents