Days Between Two Dates - ANSI SQL

I need a way to determine the number of days between two dates in SQL.

The answer should be in ANSI SQL.

+5
source share
4 answers

ANSI SQL-92 defines DATE-DATE as a return type of INTERVAL. It is assumed that you can retrieve scalars from INTERVALS using the same method as retrieving them from DATE using - appropriately - EXTRACT (4.5.3).

<expression expression> acts on a datetime or interval and returns an exact numerical value representing the value of one component of a date and time or interval.

. , , - . DATEDIFF .

"" .

SELECT EXTRACT(DAY FROM DATE('2009-01-01') - DATE('2009-05-05')) FROM DUAL;

!

+6

, RDBMS, DATE1-DATE2, SQL 92, , .

+3

, SQL-92 "-".

+1

SQL 92 :

t.date_1 - t.date_2

EXTRACT ANSI, SQL Server. :

ABS(EXTRACT(DAY FROM t.date_1) - EXTRACT(DAY FROM t.date_2)

, , .

:

  • Oracle 9i +
  • MySQL
  • Postgres
0
source

All Articles