Oracle 5.0 Reference Manual page 940

Table of Contents

Advertisement

• String otherwise.
To ensure that the result is DATETIME, you can use
DATETIME.
MySQL permits any punctuation delimiter in the
suggested delimiters. If the
MONTH, and
parts (that is, no time parts), the result is a
DAY
value.
DATETIME
Date arithmetic also can be performed using
operator:
date
+ INTERVAL
expr unit
date
- INTERVAL
expr unit
INTERVAL expr unit
the other side is a date or datetime value. For the
permitted only on the right side, because it makes no sense to subtract a date or datetime value from
an interval.
mysql>
SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND;
-> '2009-01-01 00:00:00'
mysql>
SELECT INTERVAL 1 DAY + '2008-12-31';
-> '2009-01-01'
mysql>
SELECT '2005-01-01' - INTERVAL 1 SECOND;
-> '2004-12-31 23:59:59'
mysql>
SELECT DATE_ADD('2000-12-31 23:59:59',
->
-> '2001-01-01 00:00:00'
mysql>
SELECT DATE_ADD('2010-12-31 23:59:59',
->
-> '2011-01-01 23:59:59'
mysql>
SELECT DATE_ADD('2100-12-31 23:59:59',
->
-> '2101-01-01 00:01:00'
mysql>
SELECT DATE_SUB('2005-01-01 00:00:00',
->
-> '2004-12-30 22:58:59'
mysql>
SELECT DATE_ADD('1900-01-01 00:00:00',
->
-> '1899-12-30 14:00:00'
mysql>
SELECT DATE_SUB('1998-01-02', INTERVAL 31 DAY);
-> '1997-12-02'
mysql>
SELECT DATE_ADD('1992-12-31 23:59:59.000002',
->
INTERVAL '1.999999' SECOND_MICROSECOND);
-> '1993-01-01 00:00:01.000001'
If you specify an interval value that is too short (does not include all the interval parts that would
be expected from the
unit
of the interval value. For example, if you specify a
expected to have days, hours, minutes, and seconds parts. If you specify a value like '1:10',
MySQL assumes that the days and hours parts are missing and the value represents minutes and
seconds. In other words,
MINUTE_SECOND. This is analogous to the way that MySQL interprets
'1:10'
representing elapsed time rather than as a time of day.
Because
is treated as a string, be careful if you specify a nonstring value with INTERVAL. For
expr
example, with an interval specifier of HOUR_MINUTE,
hour, 5000 minutes:
mysql>
SELECT 6/4;
-> 1.5000
mysql>
SELECT DATE_ADD('2009-01-01', INTERVAL 6/4 HOUR_MINUTE);
-> '2009-01-04 12:20:00'
Date and Time Functions
argument is a
date
INTERVAL
is permitted on either side of the
INTERVAL 1 SECOND);
INTERVAL 1 DAY);
INTERVAL '1:1' MINUTE_SECOND);
INTERVAL '1 1:1:1' DAY_SECOND);
INTERVAL '-1 10' DAY_HOUR);
keyword), MySQL assumes that you have left out the leftmost parts
'1:10' DAY_SECOND
920
[948]
to convert the first argument to
CAST()
format. Those shown in the table are the
expr
value and your calculations involve only YEAR,
DATE
value. Otherwise, the result is a
DATE
together with the
[906]
operator if the expression on
+
[906]
operator,
-
INTERVAL expr unit
of DAY_SECOND, the value of
unit
is interpreted in such a way that it is equivalent to
evaluates to
6/4
[906]
or
[906]
+
-
is
is
expr
values as
TIME
and is treated as 1
1.5000

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents