23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Relational operators<br />

212<br />

• Addition and subtraction, from left to right<br />

Date arithmetic expressions<br />

Date arithmetic expressions compute the difference between date-time expressions in terms of<br />

days or milliseconds. <strong>SQL</strong> supports these forms of date arithmetic:<br />

• Addition and subtraction of integers to and from date-time expressions<br />

• Subtraction of one date-time expression from another<br />

Syntax<br />

date_time_expr { + | - } int_expr<br />

| date_time_expr - date_time_expr<br />

date_time_expr<br />

int_expr<br />

Returns a value of type DATE or TIME or TIMESTAMP. A single date-time expression cannot<br />

mix data types, however. All elements of the expression must be the same data type.<br />

Date-time expressions can contain date-time literals, but they must be converted to DATE<br />

or TIME using the CAST, CONVERT, or TO_DATE functions.<br />

Returns an integer value. <strong>SQL</strong> interprets the integer differently depending on the data type<br />

of the date-time expression:<br />

• For DATE expressions, integers represent days<br />

• For TIME expressions, integers represent milliseconds<br />

• For TIMESTAMP expressions, integers represent milliseconds<br />

Examples The following example manipulates DATE values using date arithmetic. <strong>SQL</strong> interprets integers<br />

as days and returns date differences in units of days:<br />

SELECT C1, C2, C1-C2 FROM DTEST<br />

c1 c2 c1-c2<br />

---------------------------------------<br />

1956-05-07 1952-09-29 1316<br />

select sysdate,<br />

sysdate - 3 ,<br />

sysdate - cast ('9/29/52' as date)<br />

from dtest;<br />

sysdate sysdate-3 sysdate-convert(date,9/29/52)<br />

----------------------------------------------------------<br />

1995-03-24 1995-03-21 15516<br />

The following example manipulates TIME values using date arithmetic. <strong>SQL</strong> interprets integers<br />

as milliseconds and returns time differences in milliseconds:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!