Databases - Dates and Times

Most database applications use dates and times - this just covers the basics of how to manipulate them. Also see Fields and Calendars (how to pick a date from a calendar).

Delphi


Delphi 5.0

Delphi supports The first 3 types are Doubles, the third is a record (structure).

Dates before 12/30/1899 are negative (the OLE 2.0 standard).
In TTimeStamp, Time is stored as milliseconds after midnight.
In TDateTime, Time is stored as the fraction of a 24 hour day that has elapsed.
Some functions fail with dates before 1/1/100 AD.

Basic functions

These functions convert a DateTime to/from a string.

Ther following global variables affect how dates and times are formatted (see Currency and date/time formatting variables in the help and sysutils.pas). These useful global variables are used in the Date/Time help example ... but they are not recognized by the compiler and they were not found in the supplied source code (ie, you can not use them).

To determine the number of days in a month, use the undocumented global array MonthDays (this is not in the help).


Database Controls

When database controls are placed on a form, they have a generic Field property. To use this as a double, just reference it (DBEdit1.Field.Value returns a variant); to use date/time specific properties, you must cast it (tell the compiler to treat the field as a TDateTimeField).

TDateTimeField.GetText defaults to

when DisplayFormat is not set.

Both of these commands will set the format used to display the date in an edit field (ie, they are equilalent).

However, when you click in the field, the display shows the "edit" format - ShortDateFormat and LongTimeFormat. Notice that when you type the "dot" before DisplayFormat, Code Insight does not automatically display - instead, you must press Ctrl-Space to see the available options. DisplayFormat is not availble (will not compile) without the cast.


Missing Controls

Delphi 5 should contain several additional database controls


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Databases / Dates.html