Skip to content

Time

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

Purpose

Declares one or more Time variables.

Syntax

To declare Time variables:

Time {identifier} [{identifier}]

Where:

  • {identifier} is a variable name for the new Time variable.
  • {identifier} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z, and _ (underscore).

To declare array variables of type Time:

Time {dimension-list} {identifier} [{identifier}]

Where:

  • {dimension-list} is a list of one or more array dimensions for the array. A dimension list is declared using square brackets []. One pair of brackets is used to declare each dimension. If the array is static, then you must specify the static size of each dimension between each pair of brackets, e.g., [ {size} ]. For more information about declaring arrays, refer to Array Variable Assignments.
  • {identifier} may be between 1 and 4096 characters in length, must start with a letter, and may not contain spaces. Recommended characters are 0-9, a-z, A-Z, and _ (underscore).

What It Does

The Time command creates a variable of the Time type. This is useful for storing times and performing calculations.

A Time variable can contain a value in the range of 00:00:00 to 23:59:59.

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

String conversions to time variables are locale-specific, so use the date functions, DateSetSecond, DateSetMinute, and DateSetHour to place constant values in a Time variable.

Examples

Procedure Test
    Time tmVar
    Move (DateSetSecond(tmVar, 30)) To tmVar
    Move (DateSetMinute(tmVar, 10)) To tmVar
    Move (DateSetHour(tmVar, 10)) To tmVar
End_Procedure

This example declares a Time variable and initializes it to 10:10:30 AM.

Time[] tmClassStart

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

Time[5] tmClassStart

This example declares 1 static array variable, named tmClassStart, containing 5 elements of type Time.

Time[][3] tmClassStart

This example creates a two-dimensional dynamic array variable named tmClassStart, containing an undefined number of elements of type Time. 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

  • Time arithmetic is not supported using the Time type, but it is supported using TimeSpan and DateTime.
  • If you need to define a global Time variable, you should use the global_variable command to do so.