FORMATDATE Function

Returns a date formatted as a string.

Category: Date and Time
Returned data type: String
Note: The returned value is a string with the date formatted as a string.

Syntax

FORMATDATE(<datevar,format>)

Required Arguments

<datevar>

a date that needs to be formatted; this can be specified as field name.

<format>

a string that represents the format that needs to be applied; this can be specified as fixed string, field name, or expression.

Details

The format parameter can include any string, but the following strings are replaced with the specified values:
  • YYYY: four-digit year
  • YY: two-digit year
  • MMMM: full month in proper case
  • MMM: abbreviated three-letter month
  • MM: two-digit month
  • DD: two-digit day
  • hh: hour
  • mm: minute
  • ss: second
  • ms: millisecond
Note: The format parameters are case sensitive.
The FORMATDATE function dates should be in the format specified by ISO 8601 (YYYY-MM-DD hh:mm:ss:ms) to avoid ambiguity. Remember that date constants must start with and end with the # sign (for example, #12-February-2010#).

Examples

Example 1

// Declare a date variable and initialize
 // it to a value
date dateval
dateval = #2010-02-12#
// Declare the formatted date variable
string fmtdate
fmtdate = formatdate(dteval, "MM/DD/YY")
Results: 02/12/10

Example 2

// Declare a date variable and initialize
// it to a value
date dateval
dateval = #2010-02-12#
// Declare the formatted date variable
string fmtdate
fmtdate = formatdate(dateval, "DD MMM YYYY")
Results: 12 Feb 2010

Example 3

// Declare a date variable and initialize 
// it to a value
date dateval
dateval = #2010-02-12#
// Declare the formatted date variable
string fmtdate
fmtdate = formatdate(dateval, "MMMM DD, YYYY")
Results: February 12, 2010

Example 4

day_string=formatdate('date',"DD");
month_string=formatdate('date',"MM");
year_string=formatdate('date',"YYYY");
 
int_number='date';
date_string=formatdate(int_number,"MMM DD,YYYY");
 
df_date='date';
Results
FORMATDATE Function, Example 4, Example Code Results