Converting the date/time value into the formatted text string.

 

Syntax

function FormatDateTime(sFormat: string; dt: double): string;

 

Parameters and return values

Parameter

Type

Value

sFormat

string

the format by which the date and time value is converted into the text string;

dt

double

date/time value.

 

Specifiers for formatting

y or yy

displays the year as a two-digit number;

yyyy

displays the year as a four-digit number;

m

displays the month as a number without a leading zero if the month parameter is less than October;

mm

displays the month number with a leading zero;

mmm

displays the month as an abbreviation;

mmmm

displays the month as a full name;

d

displays the date as a number without a leading zero;

dd

displays the date as a number with a leading zero if the number less than 10;

ddd

displays the day of the week as an abbreviation;

dddd

displays the day of the week as a full name;

ddddd

displays the date in short format ("11.21.2015");

dddddd

displays the date in full format ("November 21, 2015");



c

date and time in short format ("11.21.2015 18:33:50");

h

displays the hour without a leading zero;

hh

displays the hour with a leading zero;

n

displays the minute without a leading zero;

nn

displays the minute with a leading zero;

s

displays the second without a leading zero;

ss

displays the second with a leading zero;

z

displays the millisecond without a leading zero;

zzz

displays the millisecond with a leading zero ("007");

t

displays the time in short format without seconds ("18:36");

tt

displays the time in full format ("18:36:52");



am/pm

uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon;

a/p

uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon.;

ampm

uses 12-hours time format instead of 24;

/

displays the date separator character;

:

displays the time separator character.

 

Function result

Text string of the date and time.

 

Example


var
  dt: double;
begin
  dt := Now;
 
 // working with dates
  mLogScript(FormatDateTime('m/d/y', dt), 'm/d/y');
  mLogScript(FormatDateTime('mm/dd/yy', dt), 'mm/dd/yy');
  mLogScript(FormatDateTime('ddd mmm d yyyy', dt), 'ddd mmm d yyyy');
  mLogScript(FormatDateTime('dddd, mmm d, yyyy', dt), 'dddd, mmm d, yyyy');
  mLogScript(FormatDateTime('ddddd ', dt), 'ddddd');
  mLogScript(FormatDateTime('dddddd', dt), 'dddddd');
  mLogScript(FormatDateTime('c', dt), 'c');
  
  // working with times
  mLogScript(FormatDateTime('h:n:s.z', dt), 'h:n:s.z');
  mLogScript(FormatDateTime('hh:nn:ss.zzz', dt), 'hh:nn:ss.zzz');
  mLogScript(FormatDateTime('t', dt), 't');
  mLogScript(FormatDateTime('tt', dt), 'tt');
  mLogScript(FormatDateTime('c', dt), 'c');
end.


Script work result

[19:01:19] (Log "test"): [m/d/y] 11.21.15

[19:01:19] (Log "test"): [mm/dd/yy] 11.21.15

[19:01:19] (Log "test"): [ddd mmm d yyyy] Sat, Nov 21, 2015

[19:01:19] (Log "test"): [dddd, mmm d, yyyy] Saturday, November 21 2015

[19:01:19] (Log "test"): [ddddd] 11.21.2015

[19:01:19] (Log "test"): [dddddd] November 21 2015

[19:01:19] (Log "test"): [c] 11.21.2015 19:01:19

[19:01:19] (Log "test"): [h:n:s.z] 19:1:19.513

[19:01:19] (Log "test"): [hh:nn:ss.zzz] 19:01:19.513

[19:01:19] (Log "test"): [t] 19:01

[19:01:19] (Log "test"): [tt] 19:01:19

[19:01:19] (Log "test"): [c] 21.11.2015 19:01:19

 


See also

mLogScript

Now