program DateFormats;
// Free Pascal uses FormatDateTime from the SysUtils unit,
// which is powerful and easy to use
(*
Format Codes You Can Use in Free Pascal
Here are the most useful ones:
yyyy — 4‑digit year
yy — 2‑digit year
mm — month (01–12)
mmm — short month name
mmmm — full month name
dd — day of month
ddd — short weekday name
dddd — full weekday name
hh — hour
nn — minutes
ss — seconds
am/pm — 12‑hour suffix
c — system default date/time
y — day of year
ww — week of year
q — quarter (1–4)
*)
uses
SysUtils;
var
NowDT: TDateTime;
begin
NowDT := Now; // Get current date/time
// --- Basic numeric formats ---
Writeln('[ISO 8601] YYYY-MM-DD: ', FormatDateTime('yyyy-mm-dd', NowDT));
Writeln('[European] DD/MM/YYYY: ', FormatDateTime('dd/mm/yyyy', NowDT));
Writeln('[US] MM-DD-YYYY: ', FormatDateTime('mm-dd-yyyy', NowDT));
// --- Time formats ---
Writeln('[24-hour] HH:MM:SS: ', FormatDateTime('hh:nn:ss', NowDT));
Writeln('[12-hour] HH:MM:SS AM/PM: ', FormatDateTime('hh:nn:ss am/pm', NowDT));
// --- Full date with names ---
Writeln('Full weekday + month name: ',
FormatDateTime('dddd, mmmm dd, yyyy', NowDT));
Writeln('Short weekday + month name: ',
FormatDateTime('ddd, mmm dd', NowDT));
// --- Combined date/time ---
Writeln('Full timestamp: ',
FormatDateTime('yyyy-mm-dd hh:nn:ss', NowDT));
Writeln('Locale-style: ',
FormatDateTime('c', NowDT)); // Default system format
// --- Special formats ---
Writeln('Day of year: ', FormatDateTime('y', NowDT));
Writeln('Week of year: ', FormatDateTime('ww', NowDT));
Writeln('Quarter of year: ', FormatDateTime('q', NowDT));
// --- Custom formats ---
Writeln('Long date: ', FormatDateTime('dddd, mmmm d, yyyy', NowDT));
Writeln('Short date: ', FormatDateTime('dd/mm/yy', NowDT));
Writeln('Time only: ', FormatDateTime('hh:nn', NowDT));
end.
(*
run:
[ISO 8601] YYYY-MM-DD: 2026-05-20
[European] DD/MM/YYYY: 20-05-2026
[US] MM-DD-YYYY: 05-20-2026
[24-hour] HH:MM:SS: 09:41:05
[12-hour] HH:MM:SS AM/PM: 09:41:05 am
Full weekday + month name: Wednesday, May 20, 2026
Short weekday + month name: Wed, May 20
Full timestamp: 2026-05-20 09:41:05
Locale-style: 20-5-26 09:41:05
Day of year: 26
Week of year: WW
Quarter of year: Q
Long date: Wednesday, May 20, 2026
Short date: 20-05-26
Time only: 09:41
*)