The ts_previous_valid() function

The ts_previous_valid() function returns the last element preceding the given time stamp.

Syntax

ts_tselem 
ts_previous_valid(ts_tsdesc   *tsdesc, 
                   mi_datetime *tstamp, 
                   mi_integer  *STATUS, 
                   mi_integer  *off)
tsdesc
The time series descriptor returned by ts_open().
tstamp
Points to the time stamp that follows the element returned.
STATUS
Points to an mi_integer value that is filled in on return. If no element exists before the time stamp, or if the time stamp falls before the time series origin, STATUS is set to a nonzero value. See The ts_hide_elem() function for a description of STATUS.
off
For regular time series, off points to an mi_integer value that is filled in on return with the offset of the returned element. For irregular time series, off is set to -1. This argument can be passed as NULL.

Description

The equivalent SQL function is GetPreviousValid.

Returns

The element, if any, preceding the given time stamp. The element returned must not be freed by the caller. It is overwritten after two calls to fetch an element using this tsdesc (time series descriptor).

For irregular time series, if no valid element precedes the given time stamp, NULL is returned. NULL is also returned if the given time stamp is less than or equal to the origin of the time series.