Professional Documents
Culture Documents
var
date1, date2, date3 : TDateTime; // TDateTime variables
begin
date1 := Yesterday; // Set to the start of yesterday
date2 := Date; // Set to the start of the current day
date3 := Tomorrow; // Set to the start of tomorrow
date4 := Now; // Set to the current day and time
end;
date1 is set to something like 12/12/2002 00:00:00
date2 is set to something like 13/12/2002 00:00:00
date3 is set to something like 14/12/2002 00:00:00
date4 is set to something like 13/12/2002 08:15:45
Note : the start of the day is often called midnight in Delphi documentation, but this is misleading, since it would be midnight of the
wrong day.
Jan
January
Feb
February
Mar
March
Apr
April
May
May
Jun
June
Jul
July
Aug
August
Sep
September
Oct
October
Nov
November
Dec
December
Short and long day names
It is important to note that these day arrays start with index 1 = Sunday. This is not a good standard (it is not ISO
8601 compliant), so be careful when using with ISO 8601 compliant routines such as DayOfTheWeek
var
day : Integer;
begin
for day := 1 to 12 do // Display the short and long day names
begin
ShowMessage(ShortDayNames[day]);
ShowMessage(LongDayNames[day]);
end;
end;
The ShowMessage routine display the following information:
Sun
Sunday
Mon
Monday
Tue
Tuesday
Wed
Wednesday
Thu
Thursday
Fri
Friday
Sat
Saturday
begin
// Set up our TDateTime variable with a full date and time :
// 09/02/2000 at 05:06:07.008 (.008 milli-seconds)
myDate := EncodeDateTime(2000, 2, 9, 5, 6, 7, 8);
// Use short names for the day, month, and add freeform text ('of')
ShowMessage(' ddd d of mmm yyyy = '+
FormatDateTime('ddd d of mmm yyyy', myDate));
ShowMessage('');
d/m/y = 9/2/00
dd/mm/yy = 09/02/00
ddd d of mmm yyyy = Wed 9 of Feb 2000
dddd d of mmmm yyyy = Wednesday 9 of February 2000
ddddd = 09/02/2000
dddddd = 09 February 2000
c = 09/02/2000 05:06:07
h:n:s.z = 5:6:7.008
hh:nn:ss.zzz = 05:06:07.008
t = 05:06
tt = 05:06:07
c = 09/02/2000 05:06:07
The above output uses default values of a number of formatting control variables. These are covered in the next section:
DateSeparator = /
TimeSeparator = :
ShortDateFormat = dd/mm/yyyy
LongDateFormat = dd mmm yyyy
TimeAMString = AM
TimePMString = PM
ShortTimeFormat = hh:mm
LongTimeFormat = hh:mm:ss
ShortMonthNames = Jan Feb ...
LongMonthNames = January, February ...
ShortDayNames = Sun, Mon ...
LongDayNames = Sunday, Monday ...
TwoDigitYearCenturyWindow = 50