DayOf
Function DayOf(const AValue: TDateTime): Word
Example
procedure ScriptEvent(var Value: variant);
begin
Value := DayOf(EncodeDate(2026, 7, 18)); // 18
end;
Usage
DayOf returns the day-of-month component of a TDateTime value in the range 1 through 31.
Parameters
| Name | Type | Description |
|---|---|---|
AValue | TDateTime, const | Date/time value whose day-of-month is required. Time and timezone meaning do not affect the component. |
Returns
A Word from 1 to 31 for a valid date.
Behaviour
The date portion alone determines the result. Leap years and month lengths matter to the validity of the original date, but no separate month-length calculation is performed here.
Errors
Valid TDateTime values do not raise. Unsupported non-finite or out-of-domain values are not validated by the binding.
Additional Technical Info
DayOf extracts the calendar day within the month from a TDateTime. For a valid Delphi date, the result is between 1 and 31.
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.DayOf. It calls System.SysUtils.DecodeDate(AValue, Year, Month, Result) and discards the decoded year and month.
Edge cases and quirks
DayOfTheMonthis an exact wrapper aroundDayOfin the installed Delphi source; it does not use a different ordinal convention.- Raw
TDateTimevalues before Delphi's supported year 1 boundary causeDecodeDateto return zero components. In that unsupported case this function can return0, outside the documented valid range, rather than raising locally. - The value
0.0is valid and represents 30 December 1899, soDayOf(0.0)returns30. - No timezone conversion occurs. A UTC and local value with different encoded dates can return different components.
Side effects
None.
Performance and concurrency
Constant-time calendar decoding with no allocation or shared state.
Related entries
DayOfTheMonthis the same operation under an ordinal-style name.DayOfTheYearreturns the day within the year.DecodeDatereturns year, month and day together.
External references
- Embarcadero
System.DateUtils.DayOf- documents the exact Delphi function and valid result range. - Free Pascal
DayOf- documents the compatible Free Pascal routine.