User Tools

Site Tools


date_four_byte_date_.htm
Navigation:  Language Reference > 3 - Variable Declarations > Data Types >====== DATE (four-byte date) ====== Previous pageReturn to chapter overviewNext page
label DATE [,DIM( )] [,OVER( )] [,NAME( )] [,EXTERNAL] [,DLLL] [,STATIC] [,THREAD] [,AUTO] [,PRIVATE] [,PROTECTED]

blk2blue.jpg

DATE A four-byte date.

Format:    year      mm     dd

      | …….. | …. | …. |

Bits: 31         15      7      0

Range:

year:  1 to 9999

month: 1 to 12

day:   1 to 31

DIM Dimension the variable as an array.
OVER Share a memory location with another variable.
NAME Specify an alternate, “external” name for the field.
EXTERNAL Specify the variable is defined, and its memory is allocated, in an external library. Not valid within FILE, QUEUE, or GROUP declarations.
DLL Specify the variable is defined in a .DLL. This is required in addition to the EXTERNAL attribute.
STATIC Specify the variable's memory is permanently allocated.
THREAD Specify memory for the variable is allocated once for each execution thread. Also implicitly adds the STATIC attribute on Procedure Local data.
AUTO Specify the variable has no initial value.
PRIVATE Specify the variable is not visible outside the module containing the CLASS methods. Valid only in a CLASS.
PROTECTED Specify the variable is not visible outside base CLASS and derived CLASS methods. Valid only in a CLASS.

DATE declares a four-byte date variable. This format matches the “DATE” field type used by the Btrieve Record Manager. A DATE used in a numeric expression is converted to the number of days elapsed since December 28, 1800 (Clarion Standard Date - usually stored as a LONG). The valid Clarion Standard Date range is January 1, 1801 through December 31, 9999. Using an out-of-range date produces unpredictable results. DATE fields should be used to achieve compatibility with outside files or procedures.

Example:

DueDate     DATE                      !Declare a date field
OtherDate   DATE,OVER(DueDate)        !Declare field over date field
ContactDate DATE,DIM(4)               !Array of 4 date fields
ExampleFile FILE,DRIVER('Btrieve')    !Declare a file
Record       RECORD
DateRecd       DATE,NAME('DateField') !Declare with external name
            END
           END

While a DATE data type has a unique long integer internal D-M-Y format any code using it will automatically convert it to or from a Clarion Standard Date. The only way to obtain the DATE in internal format must be done with a LONG or STRING over the DATE. In the below example code the number 5 is the standard date for Jan, 2 1801.

BT_Date  DATE
BT_Raw   LONG,OVER(BT_Date)  !Obtain DATE in internal format
 BT_Date = 5
 Message(Format(BT_Date,@d8-) &' - '& BT_Date &' - '& BT_Raw )
 !displays: 2-Jan-1801 - 5 - 118030594
 !118030594 => 07090102h  0709h => 1801

Additional Example:

!Extracts date parts w/o multiple calls to MONTH,DAY,YEAR or using FORMAT() and slicing.
GetMDY  PROCEDURE(LONG ClaDate, *LONG OutMonth, *LONG OutDay, *LONG OutYear)
BTDate  DATE,AUTO
BT      GROUP,OVER(BTDate)  !Note Little Endian reversal
Day      BYTE
Month    BYTE
Year     USHORT
       END
 CODE
 BTDate = ClaDate ! Convert LONG (Clarion Standard Date) to a Btrieve date DDMMYYYY
 OutMonth = BT.Month
 OutDay   = BT.Day
 OutYear  = BT.Year
 RETURN

See Also:

Standard Date TIME

date_four_byte_date_.htm.txt · Last modified: 2023/02/03 03:53 by carlbarnes