DAYS Function [Date and Time]

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.

DAYS ignores hours, minutes, and seconds.

Syntax

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

Parameters

Parameter

Description

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.

Returns

INT when you specify two datetime expressions.

TIMESTAMP when the second argument you specify is an integer.

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

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported by Adaptive Server Enterprise.

Related reference
CAST Function [Data Type Conversion]