SECONDS_BETWEEN scalar function

The SECONDS_BETWEEN function returns the number of full seconds between the specified arguments.

Read syntax diagramSkip visual syntax diagramSECONDS_BETWEEN(expression1 ,expression2)

The schema is SYSIBM.

expression1
An expression that specifies the first datetime value to compute the number of full seconds between two datetime values. The expression must return a value that is a DATE, TIMESTAMP, CHAR, or VARCHAR data type. In a Unicode database, the expression can also be a GRAPHIC or VARGRAPHIC data type. CHAR, VARCHAR, GRAPHIC, and VARGRAPHIC are supported by using implicit casting. If expression1 is a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it must be a valid string that is accepted by the TIMESTAMP scalar function.
expression2
An expression that specifies the second datetime value to compute the number of full seconds between two datetime values. The expression must return a value that is a DATE, TIMESTAMP, CHAR, or VARCHAR data type. In a Unicode database, the expression can also be a GRAPHIC or VARGRAPHIC data type. CHAR, VARCHAR, GRAPHIC, and VARGRAPHIC are supported by using implicit casting. If expression2 is a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it must be a valid string that is accepted by the TIMESTAMP scalar function.

If there is less than a full second between expression1 and expression2, the result is zero. If expression1 is later than expression2, the result is positive. If expression1 is earlier than expression2, the result is negative. If expression1 or expression2 contains time information, this information is also used to determine the number of full seconds. If expression1 or expression2 does not contain time information, a time of midnight (00.00.00) is used for the argument that is missing time information.

The result of the function is a BIGINT. If either argument can be null, the result can be null. If either argument is null, the result is the null value.

Examples

  1. Set the host variable NUM_SECONDS to the number of full seconds between 2012-03-01-01.00.00 and 2012-02-28-00.00.00.
       SET :NUM_SECONDS = SECONDS_BETWEEN(TIMESTAMP '2012-03-01-01.00.00', 
                                          TIMESTAMP '2012-02-28-00.00.00')
    The host variable NUM_SECONDS is set to 176400; 86400 of the seconds are incurred because of February 29, 2012.
  2. Set the host variable NUM_SECONDS to the number of full seconds between 2013-09-11-23.59.59.999999 and 2013-09-01-00.00.00.000000.
       SET :NUM_SECONDS = SECONDS_BETWEEN(TIMESTAMP '2013-09-11-23.59.59.999999', 
                                          TIMESTAMP '2013-09-01-00.00.00.000000')
    The host variable NUM_SECONDS is set to 950399 because there are 0.000001 seconds less than a full 950400 seconds between the arguments. It is positive because the first argument is later than the second argument.
  3. Set the host variable NUM_SECONDS to the number of full seconds between 2013-09-01-00.00.00.000000 and 2013-09-11-23.59.59.999999.
       SET :NUM_SECONDS = SECONDS_BETWEEN(TIMESTAMP '2013-09-01-00.00.00.000000', 
                                          TIMESTAMP '2013-09-11-23.59.59.999999')
    The host variable NUM_SECONDS is set to -950399 because there are 0.000001 seconds less than a full 950400 seconds between the arguments. It is negative because the first argument is earlier than the second argument.