Cicode Programming Reference > Cicode Function Categories > Timestamp Functions Introduction > TimestampDifference

TimestampDifference

Returns the difference between two TIMESTAMP variables as a number of milliseconds.

Syntax

TimestampDifference(TIMESTAMP Timestamp1, TIMESTAMP Timestamp2 [, INT Part [, INT bCumulative]])

Timestamp 1:

The TIMESTAMP variable 1.

Timestamp 2:

The TIMESTAMP variable 2.

Part:

The type of time units being used for the result:

0 – Result is in years.

1 – Result is in months.

2 – Result is in days.

3 - Result is in hours

4 - Result is in minutes.

5 - Result is in seconds (default).

6 - Result is in milliseconds.

bCumulative:

Defines how to pass results which values are greater than their time units (see example below).

0 – Non-cumulative

1 – Cumulative mode (default).

Return Value

The time period between Timestamp1 and Timestamp2. The value is equal or greater than zero. If error, returns 0 with an error code.

Related Functions

TimestampAdd, TimestampCurrent, TimestampSub, TimestampToStr, TimestampCreate, TimestampFormat, TimestampGetPart, TimestampToTimeInt, TimeIntToTimestamp 

Example

TIMESTAMP t1 = TimestampCreate(2008, 11, 28, 09, 01, 30);
TIMESTAMP t2 = TimestampCreate(2008, 11, 28, 09, 00, 00);
INT nTimespanCumulative = TimestampDifference(t1, t2, 5, 0);
// nTimespanCumulative is equal 90 (seconds)
INT nTimespanNonCumulative = TimestampDifference(t1, t2, 5, 1);
// nTimespanNonCumulative is equal 30 (seconds)

See Also

Timestamp Functions