FormatDate Function

Description

An Expression Designer function that returns a string expression based on the date, date format, and locale specified by the user.

Syntax

local variable = FormatDate (Date, Format, Locale) 
		

The FormatDate function syntax has the following parameters:

Date
A date string or a variable containing a date string that is valid for the specified locale. To specify the current system date, use "Current". To specify a date string, enter the desired date string in quotes ("January 5th, 2009"). For variables containing a date string, use the variable name without quotes.
Format
A date format that consists of a combination of the following elements that are valid for the specified locale:
Day
  • d – Day of month as digits with no leading zero for single-digit days ("1"-"9", "10"-"31").
  • dd – Day of month as digits with leading zero for single-digit days ("01"-"09", "10"-"31").
  • ddd – Day of week as a three-letter abbreviation (Mon, Tue, Wed, and so on, in English).
  • dddd – Day of week as its full name (Monday, Tuesday, Wednesday, and so on, in English).
Month
  • M – Month as digits with no leading zero for single-digit months ("1"-"9", "10"-"12").
  • MM – Month as digits with leading zero for single-digit months ("01"-"09", "10"-"12").
  • MMM – Month as a three-letter abbreviation (Jan, Feb, Oct, and so on, in English).
  • MMMM – Month as its full name.
Year
  • y – Year as last two digits, but with no leading zero for years less than 10 ("0"-"9", "10"-"99").
  • yy – Year as last two digits, but with leading zero for years less than 10 ("00"-"09", "10"-"99").
  • yyy – Year as last two digits, but with leading zero for years less than 10 ("00"-"09", "10"-"99").
  • yyyy – Year represented by full four digits.
Era
gg – The year-division, or era designation (Japanese Era Name calendar).
Note: Silk Test Workbench verifies if an era exists for the date and locale specified. If it exists, Silk Test Workbench uses the era for the default calendar. If it does not exist, Silk Test Workbench determines whether an era exists for the alternate calendar in the same locale. If an alternate calendar exists, Silk Test Workbench formats the entire string in the alternate calendar; otherwise, Silk Test Workbench formats the string in the default calendar and ignores the era format (gg).
Locale

In general terms, a locale defines the user's language, country and any special variant preferences, such as the formats used for dates and times, that the user wants to see in their user interface.

The Locale parameter applies a specified locale definition for how a date string is interpreted and displayed in the output of the FormatDate function. Values for this parameter are based on Windows operating system locale names. An example of a locale name for French (Canada) is "fr-CA". For a list of supported locales, refer to the "Locale Identifier Constants and Strings" topic in Microsoft's National Language Support Reference.

Note: The availability of a locale is based on your operating system version and Regional Options settings.

Remarks

All parameters are required. To use the default value of the Format or Locale parameter, enter "Default" in the expression. In the following example, the FormatDate function returns the current system date using the system date format and locale of the operating system:

FormatDate("Current", "Default", "Default")
 

The following examples show how to use the elements of the Format parameter to customize the output of the FormatDate function:

FormatDate("Jan 9, 2009", "dddd, MMM-dd-yyyy", 
 "Default") returns "Friday, Jan-09-2009"

FormatDate("Jan 9, 2009", "d/M/yy", "Default") 
 returns "9/1/09"

FormatDate("Jan 9, 2009", "yy", "Default") 
 returns "09"
 

The following example is run on an English operating system and shows how to use the Locale parameter to convert a French locale date to a Spanish locale date. This is a two step process in which you convert a non-numeric French date (2009 janvier 9) to a numeric French date (2009-01-09) format. In the second step, you convert the numeric date to a Spanish date (2009-enero-09):

FormatDate("2009 janvier 9", "yyyy-MM-dd", 
 "fr-FR") returns "2009-01-09"

FormatDate(FrNumericDate, "yyyy-MMMM-dd", "es-ES") 
 returns "2009-enero-09"