SECONDS function [Date and time]

Function

Returns the number of seconds since an arbitrary starting date and time, the number of seconds between two times, or adds an integer amount of seconds to a time.

Syntax

SECONDSdatetime-expression
| datetime-expression, datetime-expression
| datetime-expression, integer-expression )

Parameters

datetime-expression A date and time.

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

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

Examples

The following statement returns the value 3600:

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

The following statement returns the value 14400, to signify the difference between the two times:

SELECT SECONDS( '1999-07-13 06:07:12',
	'1999-07-13 10:07:12' ) FROM iq_dummy

The following statement returns the datetime value 1999-05-12 21:05:12.000:

SELECT SECONDS( CAST( '1999-05-12 21:05:07'
AS TIMESTAMP ), 5) FROM iq_dummy

Usage

The second syntax returns the number of whole seconds from the first date/time to the second date/time. The number might be negative.

Standards and compatibility