The ts_tstamp_difference() function

The ts_tstamp_difference() function subtracts one date from another and returns the number of complete intervals between the two dates.

Syntax

mi_integer
ts_tstamp_difference(mi_datetime  *date1,
                      mi_datetime *date2,
                      mi_integer  interval)
date1
The first date.
date2
The date to subtract from the first date.
interval
The interval, as described next.

Description

Before the difference is calculated, both time stamps are truncated to the given interval. For example, if the interval is an hour and the first date is 2011-01-03 01:02:03.12345, its truncated value is 2011-01-03 01:00:00.00000.

Valid values for the interval parameter can be found in tseries.h. They are:
  • TS_SECOND
  • TS_MINUTE
  • TS_HOUR
  • TS_DAY
  • TS_WEEK
  • TS_MONTH
  • TS_YEAR

Returns

The number of intervals of the type you specify between the two dates.

Example

For example, if the interval is day and the dates are 2011-01-01 00:00:00.00000 and 2011-01-01 00:00:00.00001, the result is 0. If the dates are 2011-01-01 00:00:00.0000 and 2011-01-02 00:10:00.12345, the result is 1.