From Clomosy Docs

No edit summary
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
function FormatDateTime(const Formatting string; DateTime TDateTime):string;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function FormatDateTime(const Format: string; DateTime: TclDateTime):string;
</div>


The FormatDateTime function provides rich formatting of a TclDateTime value DateTime into a string. Formatting is defined by the Formatting string. The Formatting 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.<br>
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.<br>
   
   
The following (non-Asian) formatting character strings can be used in the Formatting string:
The following (non-Asian) formatting character strings can be used in the Formatting string:<br>
   
   
:'''y''' = Year last 2 digits
:<b>y</b> = Year last 2 digits
:'''yy''' = Year last 2 digits
:<b>yy</b> = Year last 2 digits
:'''yyyy''' = Year as 4 digits
:<b>yyyy</b> = Year as 4 digits


:<b>m</b> = Month number no-leading 0
:<b>mm</b> = Month number as 2 digits
:<b>mmm</b> = Month using ShortDayNames (Jan)
:<b>mmmm</b> = Month using LongDayNames (January)


:'''m''' = Month number no-leading 0
:<b>d</b> = Day number no-leading 0
:'''mm''' = Month number as 2 digits
:<b>dd</b> = Day number as 2 digits
:'''mmm''' = Month using ShortDayNames (Jan)
:<b>ddd</b> = Day using ShortDayNames (Sun)
:'''mmmm''' = Month using LongDayNames (January)
:<b>dddd</b> = Day using LongDayNames (Sunday)
:<b>ddddd</b> = Day in ShortDateFormat
:<b>dddddd</b> = Day in LongDateFormat


:<b>c</b> = Use ShortDateFormat + LongTimeFormat
:<b>h</b> = Hour number no-leading 0
:<b>hh</b> = Hour number as 2 digits
:<b>n</b> = Minute number no-leading 0
:<b>nn</b> = Minute number as 2 digits
:<b>s</b> = Second number no-leading 0
:<b>ss</b> = Second number as 2 digits
:<b>z</b> = Milli-sec number no-leading 0s
:<b>zzz</b> = Milli-sec number as 3 digits
:<b>t</b> = Use ShortTimeFormat
:<b>tt</b> = Use LongTimeFormat


:'''d''' = Day number no-leading 0
:<b>am/pm</b> = Use after h : gives 12 hours + am/pm
:'''dd''' = Day number as 2 digits
:<b>a/p</b> = Use after h : gives 12 hours + a/p
:'''ddd''' = Day using ShortDayNames (Sun)
:<b>ampm</b> = As a/p but TimeAMString,TimePMString
:'''dddd''' = Day using LongDayNames  (Sunday)
:<b>/</b> = Substituted by DateSeparator value
:'''ddddd''' = Day in ShortDateFormat
:<b>:</b> = Substituted by TimeSeparator value
:'''dddddd''' = Day in LongDateFormat


:'''c''' = Use ShortDateFormat + LongTimeFormat
<b>Example</b><br>
:'''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


<pre>
:'''am/pm''' = Use after h : gives 12 hours + am/pm
var
:'''a/p''' = Use after h : gives 12 hours + a/p
    myDate : TDateTime;
:'''ampm''' = As a/p but TimeAMString,TimePMString
:'''/''' = Substituted by DateSeparator value
{
:''':''' = Substituted by TimeSeparator value
    myDate = '20.02.2023 12:24:26';
 
'''Example:'''<br>
    ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate));
:'''Base Syntax'''
    ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate));
  var
    // Use short names for the day, month, and add freeform text ('of')
    myDate : TDateTime;
    ShowMessage('ddd d of mmm yyyy = '+FormatDateTime('ddd d of mmm yyyy', myDate));
 
  begin
    // Use long names for the day and month
    myDate := '20.02.2023 12:24:26';
    ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate));
 
    ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate));
    // Use the ShortDateFormat settings only
    ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate));
    ShowMessage('ddddd = '+FormatDateTime('ddddd', 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 the LongDateFormat settings only
 
    ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate));
    // Use long names for the day and month
    ShowMessage('dddd d of mmmm yyyy = '+FormatDateTime('dddd d of mmmm yyyy', myDate));
    ShowMessage('c = '+FormatDateTime('c', myDate));
 
}
    // Use the ShortDateFormat settings only
</pre>
    ShowMessage('ddddd = '+FormatDateTime('ddddd', myDate));
 
    // Use the LongDateFormat settings only
    ShowMessage('dddddd = '+FormatDateTime('dddddd', myDate));
 
    ShowMessage('c = '+FormatDateTime('c', myDate));
  end;
 
:'''TRObject Syntax'''


  var
<b>Output:</b><br>
    myDate : TDateTime;
<div class="alert alert-success" role="alert" data-bs-theme="light">
 
d.m.y = 20.2.23<br>
  {
dd.mm.yy = 20.02.23<br>
    myDate = '20.02.2023 12:24:26';
ddd d of mmm yyyy = Mon 20 of Feb 2023<br>
 
dddd d of mmmm yyyy = Monday 20 of February 2023<br>
    ShowMessage('d.m.y = '+FormatDateTime('d.m.y', myDate));
ddddd = 20.02.2023<br>
    ShowMessage('dd.mm.yy = '+FormatDateTime('dd.mm.yy', myDate));
dddddd = 20 February 2023 Monday<br>
    // Use short names for the day, month, and add freeform text ('of')
c = 20.02.2023 12:24:26
    ShowMessage('ddd d of mmm yyyy = '+FormatDateTime('ddd d of mmm yyyy', myDate));
</div>
 
    // 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:'''<br>
<h2> See Also </h2>
d.m.y = 20.2.23
* [[System_Library#Date_and_Time_Functions | Date and Time Functions]]
dd.mm.yy = 20.02.23
{{#seo:|title=FormatDateTime Using in Clomosy - Clomosy Docs}}
ddd d of mmm yyyy = Mon 20 of Feb 2023
{{#seo:|description=Learn how to use the FormatDateTime function in Clomosy to format TclDateTime values into customized date and time strings for display or processing.}}
dddd d of mmmm yyyy = Monday 20 of February 2023
ddddd = 20.02.2023
dddddd =  20 February 2023 Monday
c = 20.02.2023 12:24:26

Latest revision as of 15:04, 24 December 2024

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