See Also: Declaring Variables, Variable Declaration Commands, Time and Date Functions, Struct, String Functions
Declares one or more Date variables.
To declare Date variables
Date {date-identifier} [… {date-identifier}]
Where
Where {identifier} is a variable name for the new date 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 Date
Date{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. i.e. [{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).
The Date command creates variables that contain date values.
Multiple variables may be declared on one command line, with their names separated from each other by spaces.
Date arithmetic works according to the following table:
Operation |
Result |
Date + Integer |
Date |
Integer + Date |
Date |
Date + Date |
Date |
Date - Integer |
Date |
Date - Date |
Integer |
Date dAnniversary dSpousesBirthday dVacation dDeadline
This example declares four date variables: dAnniversary, dSpousesBirthday, dVacation, and dDeadline.
Date[] dBirthdays
This example declares 1 dynamic array variable, named dBirthdays, containing an undefined number of elements of type date.
Date[5] dBirthdays
This example declares 1 static array variable, named dBirthdays, containing 5 of elements of type date.
Date[][3] dBirthdays
This example creates a two-dimensional dynamic array variable named dBirthdays, containing an undefined number of elements of type date. 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.
Dates are stored as Julian numbers. Julian dates are integers equal to the number of days from Day 1, Year 0 to the date. Julian dates were widely used because they require little storage and are easy to do calculations with since they are integer values.
Years may be in the range of 01 (or 0001) to 2500.
If you are using a field_mask, years may be in the range of 01 to 2200.
You may do calculations on dates. Subtracting one date from another will yield the number of days between them. You may also add a number of days to a date. Here is a simple example that shows Y2K compliance. Notice it uses both 2-digit and 4-digit year constants to show how the epoch setting works.
Object oTest Is A Button
Function DaysAgo Date dSomeDate Returns Integer
Date dToday
Integer iDaysBetween
SysDate dToday
Move (dToday - dSomeDate) To iDaysBetween
Function_Return iDaysBetween
End_Function
Procedure Test Date dTest
Integer iDaysAgo
Move (DaysAgo(self, dTest)) To iDaysAgo
If (iDaysAgo > 0);
Showln dTest " was " iDaysAgo " days ago."
Else;
Showln dTest " is " (-iDaysAgo) " days from now."
End_Procedure
Procedure OnClick
// Test various 2 and 4 digit dates.
Send Test "01/01/1980"
Send Test "01/01/80"
Send Test "01/01/2000"
Send Test "01/01/00"
Send Test "01/01/2010"
Send Test "01/01/10"
End_Procedure
End_Object
The
display of the date depends on the format chosen. Typically, DataFlex
will conform to your Windows operating system locale settings. Use
the Set_Attribute command
and the DF_DATE_FORMAT
attribute to change the attribute from the default.
DF_DATE_USA 12/31/2005
DF_DATE_EUROPEAN 31/12/2005
DF_DATE_MILITARY 2005/12/31
You may use string functions (left, right, mid, etc.) to extract date information from a Date variable. The string operation will be performed on a string representation of the date that is consistent with the date format in effect.
If an illegal value (such as 13/31/05) is moved to any Date-type variable, DataFlex will declare an error.
DataFlex is Y2K-robust. We recommend using 4-digit years in your date fields. If 2-digit years are used, the epoch settings must be set correctly so that the correct century (19xx or 20xx) is selected for any given date with 2-digit years. Epoch settings are made with the Set_Date_Attribute command. By default, Epoch settings are set to use 4-digit years.
You may convert a two digit year date to a four digit year date by adding 01/01/1900 or 693975 to the date.
If you need to define a global Date variable, you should use the global_variable command to do so.