DAYS function [Date and time]

Function

Returns the number of days since an arbitrary starting date, returns the number of days between two specified dates, or adds the specified integer-expression number of days to a given date.

Syntax

DAYSdatetime-expression )
|   ( datetime-expression, datetime-expression )
|   ( datetime-expression, integer-expression )

Parameters

datetime-expression A date and time.

integer-expression The number of days to be added to the datetime-expression. If the integer-expression is negative, the appropriate number of days are subtracted from the date/time. If you supply an integer expression, the datetime-expression must be explicitly cast as a date.

For information on casting data types, see “CAST function [Data type conversion]”.

DAYS ignores hours, minutes, and seconds.

Examples

The following statement returns the integer value 729948:

SELECT DAYS( '1998-07-13 06:07:12' ) FROM iq_dummy

The following statement returns the integer value -366, which is the difference between the two dates:

SELECT DAYS( '1998-07-13 06:07:12',
'1997-07-12 10:07:12' ) FROM iq_dummy

The following statement returns the value 1999-07-14:

SELECT DAYS( CAST('1998-07-13' AS DATE ), 366 )
FROM iq_dummy

Standards and compatibility