To some extent, you can convert a value from one temporal type
to another. However, there may be some alteration of the value
or loss of information. In all cases, conversion between
temporal types is subject to the range of legal values for the
resulting type. For example, although
DATE,
DATETIME, and
TIMESTAMP values all can be
specified using the same set of formats, the types do not all
have the same range of values.
TIMESTAMP values cannot be
earlier than 1970 UTC or later than
'2038-01-19 03:14:07' UTC. This means that a
date such as '1968-01-01', while legal as a
DATE or
DATETIME value, is not valid as a
TIMESTAMP value and is converted
to 0.
Conversion of DATE values:
Conversion of DATETIME and
TIMESTAMP values:
Conversion of TIME values:
MySQL converts a time value to a date or date-and-time value by
parsing the string value of the time as a date or date-and-time.
This is unlikely to be useful. For example,
'23:12:31' interpreted as a date becomes
'2032-12-31'. Time values not valid as dates
become '0000-00-00' or
NULL.
As of MySQL 4.1.13, conversion of
TIME or
DATETIME values to numeric form
(for example, by adding +0) results in a
double-precision value with a microseconds part of
.000000:
mysql>SELECT CURTIME(), CURTIME()+0;+-----------+---------------+ | CURTIME() | CURTIME()+0 | +-----------+---------------+ | 10:41:36 | 104136.000000 | +-----------+---------------+ mysql>SELECT NOW(), NOW()+0;+---------------------+-----------------------+ | NOW() | NOW()+0 | +---------------------+-----------------------+ | 2007-11-30 10:41:47 | 20071130104147.000000 | +---------------------+-----------------------+
Before MySQL 4.1.13, the conversion results in an integer value with no microseconds part.

User Comments
Add your own comment.