DateOf
Function DateOf(const AValue: TDateTime): TDateTime
Example
procedure ScriptEvent(var Value: variant);
var
Timestamp: TDateTime;
begin
Timestamp := EncodeDate(2026, 7, 18) + EncodeTime(14, 30, 0, 0);
Value := DateOf(Timestamp); // 18 July 2026 at midnight
end;
Usage
DateOf removes the time component by truncating a TDateTime value to its date portion.
Parameters
| Name | Type | Description |
|---|---|---|
AValue | TDateTime, const | Date/time value from which to remove the time component. |
Returns
Trunc(AValue), normally representing the same calendar date at midnight.
Behaviour
For an ordinary encoded value, every timestamp on the same day produces the same result. The routine neither rounds nor validates the floating value and does not convert between local time and UTC.
Errors
Valid finite values do not raise. The function does not validate NaN, infinity or an out-of-domain numeric date.
Usage notes
Use DateOf when you already have a timestamp. Use Date only when you specifically need the host's current local date.
Additional Technical Info
DateOf removes the time of day from an existing TDateTime value without reading a clock or applying timezone rules. It returns the value's integral Delphi date component.
The example is fictional, deterministic and source-reviewed. It was not executed by the documentation workflow.
Implementation
The DateUtils import binds directly to Delphi 37.0 System.DateUtils.DateOf. Its entire terminal implementation is Result := Trunc(AValue).
Edge cases and quirks
- For pre-epoch values, Delphi encodes the time as the magnitude of a negative fraction.
Truncstill removes that time according to Delphi's convention; do not replace it withFloor, which would select a different integer for negative values. - Floating-point arithmetic can produce a value just across an intended midnight boundary. Because
DateOfsimply truncates, it can then return the adjacent date. Embarcadero recommends rounding an imprecisely calculated value before applyingDateOfwhen this risk exists. - A result of
0.0is the valid Delphi epoch date, 30 December 1899, not an error sentinel. - Free Pascal implements the same
Truncoperation, but its reference is compatibility information rather than the runtime used by Velox.
Side effects
None.
Performance and concurrency
Constant-time scalar truncation with no allocation or shared state.
Related entries
Dateobtains the current local date.DecodeDatereturns year, month and day as separate values.CompareDatecompares two date portions without returning them.
External references
- Embarcadero
System.DateUtils.DateOf- documents the exact routine and its calculated-value precision warning. - Free Pascal
DateOf- documents the compatible truncation-based implementation.