TimeSpan

See Also: Declaring Variables, Variable Declaration Commands, Time and Date Functions, Struct, Date, DateTime, Time

Purpose

Declares one or more TimeSpan variables.

Syntax

To declare TimeSpan variables

TimeSpan {identifier} [… {identifier}]

Where

To declare array variables of type TimeSpan

TimeSpan{dimension-list} {identifier} […{identifier}]

Where

What It Does

The TimeSpan command declares variables of the TimeSpan type.

The purpose of a TimeSpan variable is to store the result of a calculation between DateTime or Time variables. TimeSpan can store a span of time of up to 65,535 days.

Use TimeSpan manipulation functions SpanAddDay, SpanAddHour, SpanAddMillisecond, SpanAddMinute and SpanAddSecond place constant values in a TimeSpan variable.

Multiple variables may be declared on one command line, with their names separated from each other by spaces.

TimeSpan cannot contain a negative value. The value is a span of time and is always positive.

Typecasting between DateTime and TimeSpan

When you Move data between DateTime, TimeSpan and Date types automatic casting occurs as follows:

DateTime and TimeSpan Arithmetic

DateTime and TimeSpan arithmetic works according to the following table:

Operation

Result

DateTime + DateTime

error

DateTime + TimeSpan

DateTime

TimeSpan + TimeSpan

TimeSpan

TimeSpan - TimeSpan

TimeSpan (result is always a positive difference)

DateTime - DateTime

TimeSpan (result is always a positive difference)

DateTime - TimeSpan

DateTime

TimeSpan + DateTime

error

TimeSpan - DateTime

error

Examples

Procedure Test

    TimeSpan tsVar

 

    Move (DateSetSecond(tsVar, 30)) To tsVar

    Move (DateSetMinute(tsVar, 10)) To tsVar

    Move (DateSetHour(tsVar, 10))   To tsVar

    Move (DateSetDay(tsVar, 30))    To tsVar

End_Procedure

This example declares a TimeSpan variable, then initializes its value to 30 days, 10 hours, 10 minutes and 30 seconds.

 

TimeSpan[] tsIntervals

This example declares 1 dynamic array variable, named tsIntervals, containing an undefined number of elements of type TimeSpan.

TimeSpan[5] tsIntervals

This example declares 1 static array variable, named tsIntervals, containing 5 of elements of type TimeSpan.

TimeSpan[][3] tsIntervals

This example creates a two-dimensional dynamic array variable named tsIntervals, containing an undefined number of elements of type TimeSpan. Conceptually, this represents a rectangular array with an undefined number of rows, each of 3 columns.

You can declare dynamic multi-dimensional arrays where all dimensions are dynamic; these are called jagged arrays.

Notes