From Clomosy Docs

Revision as of 15:04, 24 December 2024 by ClomosyAdmin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The FormatDateTime function provides rich formatting of a TclDateTime value DateTime into a string. Formatting is defined by the Format string. The Format string can comprise a mix of ordinary characters (that are passed unchanged to the result string), and data formatting characters. This formatting is best explained by the example code.

The following (non-Asian) formatting character strings can be used in the Formatting string:

y = Year last 2 digits
yy = Year last 2 digits
yyyy = Year as 4 digits
m = Month number no-leading 0
mm = Month number as 2 digits
mmm = Month using ShortDayNames (Jan)
mmmm = Month using LongDayNames (January)
d = Day number no-leading 0
dd = Day number as 2 digits
ddd = Day using ShortDayNames (Sun)
dddd = Day using LongDayNames (Sunday)
ddddd = Day in ShortDateFormat
dddddd = Day in LongDateFormat
c = Use ShortDateFormat + LongTimeFormat
h = Hour number no-leading 0
hh = Hour number as 2 digits
n = Minute number no-leading 0
nn = Minute number as 2 digits
s = Second number no-leading 0
ss = Second number as 2 digits
z = Milli-sec number no-leading 0s
zzz = Milli-sec number as 3 digits
t = Use ShortTimeFormat
tt = Use LongTimeFormat
am/pm = Use after h : gives 12 hours + am/pm
a/p = Use after h : gives 12 hours + a/p
ampm = As a/p but TimeAMString,TimePMString
/ = Substituted by DateSeparator value
: = Substituted by TimeSeparator value

Example

 var
    myDate : TDateTime;
 
 {
    myDate = '20.02.2023 12:24:26';
 
    ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate));
    ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate));
    // 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));
 
    // Use long names for the day and month
    ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate));
 
    // Use the ShortDateFormat settings only
    ShowMessage('ddddd = '+FormatDateTime('ddddd', myDate));
 
    // Use the LongDateFormat settings only
    ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate));
 
    ShowMessage('c = '+FormatDateTime('c', myDate));
 }

Output:

See Also