DateTime

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

Purpose

Declares one or more DateTime variables.

Syntax

To declare DateTime variables

DateTime {identifier} [… {identifier}]

Where

To declare array variables of type DateTime

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

Where

What It Does

The DateTime command declares DateTime variables. This is useful for storing dates and performing calculations.

A DateTime variable can contain a value in the range of 1/1/-32768 12:00:00.000 AM to 12/31/32767 11:59:59.999 PM.

String conversions to DateTime variables are locale specific, so use the DateSet function to set a date and the DateAddXXX (DateAddDay, DateAddHour, DateAddMillisecond, DateAddMinute, DateAddMonth, DateAddSecond, DateAddYear) functions to place constant values in a DateTime variable.

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

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 (result is always a positive difference)

TimeSpan + DateTime

error

TimeSpan - DateTime

error

 

Examples

Procedure Test

    DateTime dtVar

 

    Move (DateSetMillisecond(dtVar, 10))   To dtVar

    Move (DateSetSecond(dtVar, 30))        To dtVar

    Move (DateSetMinute(dtVar, 10))        To dtVar

    Move (DateSetHour  (dtVar, 10))        To dtVar

    Move (DateSetDay   (dtVar, 30))        To dtVar

    Move (DateSetMonth (dtVar, 1))         To dtVar

    Move (DateSetYear  (dtVar, 2006))      To dtVar

End_Procedure

This example declares a DateTime variable and initializes it to 01/30/2006, 10:10:30.01 am.

DateTime dtNow

TimeSpan tsWeek

 

move (CurrentDateTime()) to dtNow

move (DateSetDay(tsWeek, 7)) to tsWeek

move (DtNow + tsWeek) to dtNow

This example adds one week to the current date and time.

 

DateTime[] dAppointments

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

DateTime[5] dAppointments

This example declares 1 static array variable, named dAppointments, containing 5 of elements of type DateTime.

DateTime[][3] dAppointments

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