Grade 12 · Practical
Delphi date and time functions
Programming Fundamentals · about 3 min
Delphi represents dates and times as a TDateTime. A family of functions reads, calculates with, and formats them.
Key points- `Now` = current date+time; `Date` = today; `Time` = current time.
- `DaysBetween`, `MonthsBetween`, `YearsBetween` (Math/DateUtils unit) measure spans — e.g. a person's age.
- `FormatDateTime('yyyy-mm-dd', d)` produces a formatted string for display.
- Add the `DateUtils` unit to the uses clause for the Between functions.
- TDateTime — Delphi's date/time value type.
- FormatDateTime — formats a TDateTime as a readable string.
EXAM TIP
to compute age, use `YearsBetween(Now, dob)`; remember to add DateUtils to uses.