TDateTime data type is used to store date and/or time values.

Internally, TDateTime is represented as a floating-point number.

The default value for this data type is 12.00 a.m. on 30/12/1899.

The integral part of a TDateTime value is the number of days that have passed since 30 Dec 1899.

The fractional part of the TDateTime value is the time - the fraction of a 24 hour day that has elapsed, e.g. 0 represents midnight and 0.5 represents noon midday.

Declaration: var myvariable : TDateTime

The following is an example of the use of TDateTime.

procedure ScriptEvent (var Value : variant);
var myvariable : TDateTime;
begin
myvariable :=Date; //Date function returns the current date
LogInfo('The date is ' +FormatDateTime('dd/mm/yyyy', myvariable));
end;

Following are some examples of TDateTime values in numeric format and their corresponding dates and times.

Numeric Value

Date and Time

0

30 December 1899 12:00 am

2.75

1 January 1900 6:00 pm

-1.25

29 December 1899 6:00 am

35065

1 January 1996 12:00 am

44275.2083

21 March 2021 5:00 pm

45093.0833

16 June 2023 2 a.m.

To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative.

So taking the dates above and ignoring the times, the difference between 21 March 2021 and 16 June 2023 is 818 days.

But if you include the time for a more accurate result, the difference is 817.875.

Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive.

To set a TDateTime variable to today + 10 days, you can use the following sample script -

DateVariable := Date + 10;

When working with negative TDateTime values, computations must handle the time portion separately.

The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value.

For example, 6:00 am on 29-Dec-1899 is –1.25 - being -1 for the date (the day before 0 date 30-Dec-1899), and .25 for the time (6/24 = .25).

This value is not taken as –1 + 0.25, which would equate mathematically to –0.75.

There are no TDateTime values between –1 and 0, i.e. the zero (0) day 30-Dec-1899 and the day before which is the minus 1 (-1) day of 29-Dec-1899.

If a field within a File Definition is specified as DateTime then it will require a display format for it to correctly be read/written to the file.

Please refer to Format Specifiers for more information.