Format Date Time
Format Date Time
Function
Description Example code : Showing all of the date field formatting data types
DatteSepara
ator The ccharacterr used to
separate display date E
Example wing the
e code : Show e effect of loca
al date format
f setting
gs
fields
s
DatteTimeTooStr Conv verts TDateTime da ate
and ttime values to a v
var
stringg myDate
e : TDa e;
ateTime
DatteTimeTooString Rich formattin ng of a
TDatteTime va ariable intto a b
begin
stringg // Set
t up ou teTime variabl
ur TDat v le with
h a full
l date and ti
ime :
Lon
ngDateFo ormat Long version o of the datte // 5th
h of Ju 49 at 01
une 204 1:02:03
3.004 (.004 milli-s
m seconds
s)
to strring form
mat //
Lon
ngDayNa ames An arrray of daays of thee
// Not
te that s treate
t 49 is ed as 2049
2 as
s follow
ws :
week k names, starting 1 =
Sund day
// TwoDigit
T tYearCe
enturyW
Window =>
= 50
Lon
ngMonthNames An arrray of daays of thee // C
Current
t year =>
= 20088 (at time
t of writin
ng)
montth names s, starting
g1 // tract TwoDigit
Subt T tYearCe
enturyW
Window =>
= 19588
= Jannuary // igit yea
2 di ar to be
b convverted =>
= 49
Lon
ngTimeFo ormat Long version o of the tim
me // Coompare with the
t last
t 2 dig
gits of
f 1958 =>
= Lesss
to strring form
mat // So t ar is in
the yea n the next
n ce
entury =>
= 20499
ShoortDateF
Format Compact vers sion of thee // (58
8 would onverted
d be co d to 19
958)
date to string format
ShoortDayNaames An arrray of daays of thee myDate
e := St teTime('
trToDat '05/06/
/49 01:02:03.0
004');
week k names, starting 1 =
Sund day
// Dem
monstra fault lo
ate def ocale setting
s gs
ShoortMonth
hNames An arrray of daays of thee
montth names s, starting
g1
= Jann // Use
e the D
DateSepparator and Ti
imeSepa
arator values
v
ShoortTimeF
Format Shorrt version of the tim me ShowMe
essage(
('dd/mmm/yy hh:
:nn:ss = '+
to strring form
mat tDateTim
Format me('dd/
/mm/yy hh:nn:s
ss', my
yDate));
StrT
ToDateTTime Conv verts a daate+time
stringg into a T
TDateTime // Use
e Short Names
tMonthN
valuee ShowMe
essage(
(' mmm = '+Fo
ormatDat
teTime(
('mmm', myDate
e));
Tim
meAMString Determines AM value in
DateT TimeToSttring // Use
e LongM ames
MonthNa
proceedure
ShowMe
essage(
(' mmmm = '+Fo
ormatDat
teTime(
('mmmm', myDat
te));
Tim
mePMStriing Determines PM M value in
DateT TimeToSttring
proceedure // Use
e Short mes
tDayNam
Tim
meSeparaator The ccharacterr used to ShowMe
essage(
(' ddd = '+Fo
ormatDat
teTime(
('ddd', myDate
e));
separate display time
fields
s // Use
e LongD
DayName
es
TwooDigitYe
earCentuuryWindo
ow Sets the centu ury threshold ShowMe
essage(
(' dddd = '+Fo
ormatDat
teTime(
('dddd', myDat
te));
for 2 digit yeaar string
conversions // Use
e the S
ShortDa
ateForma
at stri
ing
ShowMe
essage(
(' ddddd = '+Fo
ormatDat
teTime(
('ddddd
d', myDa
ate));
Down
nload this
s web site
e as a Win
ndows prrogram. // Use
e the L
LongDat
teFormat
t strin
ng
ShowMe
essage(
(' d
dddddd = '+Fo
ormatDat
teTime(
('ddddd
dd', myD
Date));
;
// Use
e the T
TimeAmS
String
ShowMe
essage(
(' h
hhampm = '+Fo
ormatDat
teTime(
('hhamp
pm', myD
Date));
;
// Use
e the S
ShortTi
imeForma
at stri
ing
ShowMe
essage(
(' t = '+Fo
ormatDat
teTime(
('t', myDate))
m );
// Use
e the L
LongTim
meFormat
t strin
ng
ShowMe
essage(
(' tt = '+Fo
ormatDat
teTime(
('tt', myDate)
));
// Use
e the T
TwoDigiitCentur
ryWindo
ow
ShowMe
essage(
(' dd/mm
m/yyyy = '+
Format
tDateTim
me('dd/
/mm/yyy
yy', myD
Date));
;
ShowMe
essage(
('');
// Now
w chang
ge the default
ts
DateSe
eparato
or := '-'
';
TimeSe
eparato
or := '_'
';
ShortD
DateFor
rmat := 'dd
d/mmm/y
yy';
LongDa
ateForm
mat := 'dd
ddd dd of mmm
mm of yy
yyy';
TimeAM
MString
g := 'mo
orning'
';
TimePM
MString
g := 'af
fternoo
on';
ShortT
TimeFor
rmat := 'hh
h:nn:ss
s';
LongTi
imeForm
mat := 'hh
h : nn : ss . zzz';
ShortM
MonthNa
ames[6] := 'JU
UN';
LongMo
onthNam
mes[6] := 'JUUNE';
ShortD
DayName
es[1] := 'SU
UN';
LongDa
ayNames
s[1] := 'SU
UNDAY';
;
TwoDig
gitYear
rCentur
ryWindow
w := 75
5; // This
T mea
ans 49 is tre
eated as
s 1949
// Set
t up ou
ur TDat
teTime variabl
v le with
h the sa
ame val
lue as before
// exc
cept th
hat we must us
se the new da
ate and time separat
s tors
// The TwoDigitYearCenturyWindow variable only takes effect here
myDate := StrToDateTime('09-02-49 01_02_03.004');
// Use ShortMonthNames
ShowMessage(' mmm = '+FormatDateTime('mmm', myDate));
// Use LongMonthNames
ShowMessage(' mmmm = '+FormatDateTime('mmmm', myDate));
// Use ShortDayNames
ShowMessage(' ddd = '+FormatDateTime('ddd', myDate));
// Use LongDayNames
ShowMessage(' dddd = '+FormatDateTime('dddd', myDate));