FormatDateTime (open)

Returns a string containing a formatted date and time.

Syntax

LOADLIB "wh::datetime.whlib";

STRING FUNCTION FormatDateTime(STRING formatstring, DATETIME date, STRING datetexts)

Parameters

STRING formatstring

Specifies the way the DateTime value should be formatted.

DATETIME date

The DateTime value to format

STRING datetexts

Specifies the texts for am, pm, all months and days in their full name and their 2 or 3 character abbreviation format. The default language is English. "NL" switches the language to Dutch, "DE" switches to German and "JP" to Japanese. It is also possible to specify your own DateTime language string where you separate the substrings with semicolons. This string should be in the following format: "am;pm;January;...;December;Monday;...;Sunday;Jan;...;Dec;Mon;...;Sun;"

Return value

STRING

A string with the formatted date and time. If MAX_DATETIME or an invalid date value was entered, the function returns an empty string

Description

FormatDateTime() returns a string, containing the given date and time in a user-specified format. Optionally, language-specific strings for month and day names may be specified through the datetexts parameter. By default the English language strings will be used.

The following formatting can be used:

Code Effect
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%d Two-digit day of month (01 - 31)
%#d Two-digit day of month, remove any leading zeros
%H Hour of the day, 24 hour day
%#H Hour of the day, 24 hour day, remove any leading zeros
%&H Hours since 1-1-1
%#&H Hours since 1-1-1, remove any leading zeros
%I Two-digit hour, 12 hour day (01 - 12)
%#I Two-digit hour, 12 hour day, remove any leading zeros
%j Three-digit day of year (001 - 366)
%#j Three-digit day of year, remove any leading zeros
%m Two-digit month number (01 - 12)
%#m Two-digit month number, remove any leading zeros
%M 2-digit minute (00 - 59)
%#M 2-digit minute, remove leading any zeros
%p Either "am" or "pm", depending on hour
%Q Three-digit millisecond (000-999)
%#Q Three-digit millisecond, remove any leading zeros
%S Two-digit second (00 - 59)
%#S Two-digit second, remove any leading zeros
%V Two-digit week number (00 - 52)
%#V One-digit week number (0 - 52)
%y Two-digit year without century (00 - 99)
%#y Two-digit year without century, remove any leading zeros
%Y Year with century
%#Y Year with century, remove any leading zeros

Examples

// The current date and time in German in the format: 01 Januar 2005
STRING example1 := FormatDateTime( "%d %B %Y"
                                  ,GetCurrentDateTime()
                                  ,"DE");

// The current day of the week in the Dutch language, using the
// parameter datetexts as language switch.
// The date format is <abbreviated> - <full>.
STRING example2 := FormatDateTime( "%a - %B "
                                  ,GetCurrentDateTime()
                                  ,"NL");

// The current day of the week in the Dutch language, using the
// parameter datetexts as a string which specifies the texts of
// the months and days.
// The date format is <abbreviated> - <full>.
// Please note there may not be any spaces, linebreaks etc.
// between the the timetext strings! The result is the same as in
// example 3.
STRING example3 := FormatDateTime("%a - %B ", GetCurrentDateTime(),
"am;pm;Januari;Februari;Maart;April;Mei;Juni;Juli;Augustus;September;
Oktober;November;December;Maandag;Dinsdag;Woensdag;Donderdag;Vrijdag;
Zaterdag;Zondag;Jan;Feb;Mar;Apr;Mei;Jun;Jul;Aug;Sep;Okt;Nov;Dec;Ma;
Di;Wo;Do;Vr;Za;Zo");