DateFormat(date [, mask ])

Description

Returns a formatted date/time value. If no mask is specified, DateFormat returns the date value in the dd-mmm-yy format. DateFormat supports dates that have the U.S. date format. For international date support, use LSDateFormat.

Category

Date and time functions

See also

Now, CreateDate, TimeFormat, ParseDateTime

Parameters

Parameter
Description
date
Date/time object in the range 1601 AD-9999 AD.
mask
Set of characters that show how ColdFusion displays a date:
  • d Day of the month as digits; no leading zero for single-digit days.
  • dd Day of the month as digits; leading zero for single-digit days.
  • ddd Day of the week as a three-letter abbreviation.
  • dddd Day of the week as its full name.
  • m Month as digits; no leading zero for single-digit months.
  • mm Month as digits; leading zero for single-digit months.
  • mmm Month as a three-letter abbreviation.
  • mmmm Month as its full name.
  • y Year as last two digits; no leading zero for years less than 10.
  • yy Year as last two digits; leading zero for years less than 10.
  • yyyy Year represented by four digits.
  • gg Period/era string. Currently ignored. Reserved for future use.

Usage

When passing a date/time value as a string, enclose it in quotes. Otherwise, it is interpreted as a number representation of a date/time object.


Note

You can pass the CreateDate function or Now function as the date parameter of DateFormat: #DateFormat(CreateDate(2001, 3, 3))#


If the switch is set, the default date format returned by the DateFormat function cannot be parsed in an expression. However, if you specify a mask, indicating the correct order, such as, mm/dd/yyyy, the date returned by this function can be parsed.

Example

<!--- This example shows the types of output with DateFormat --->
<html>
<head>
<title>
DateFormat Example

</title>
</head>

<cfset todayDate = Now()>
<body>
<H3>DateFormat Example</H3>

<P>Today's date is <cfoutput>#todayDate#</cfoutput>.

<P>Using DateFormat, we can display that date in different ways:
<cfoutput>
<UL>
    <LI>#DateFormat(todayDate)#
    <LI>#DateFormat(todayDate, "mmm-dd-yyyy")#
    <LI>#DateFormat(todayDate, "mmmm d, yyyy")#
    <LI>#DateFormat(todayDate, "mm/dd/yyyy")#
    <LI>#DateFormat(todayDate, "d-mmm-yyyy")#    
    <LI>#DateFormat(todayDate, "ddd, mmmm dd, yyyy")#    
    <LI>#DateFormat(todayDate, "d/m/yy")#
</UL>    
    
</cfoutput>    

</body>
</html>