DateFormat

Returns a formatted date/time value. If no mask is specified, DateFormat function returns date value using the dd-mmm-yy format.

See also Now, CreateDate, and ParseDateTime.

Syntax

DateFormat(date [, mask ])
date

Date/time object in the period from 1601 AD to 9999 AD.

mask

Set of characters that are used to show how ColdFusion should display the date:

Usage

When passing a date/time value as a string, make sure it is enclosed in quotes. Otherwise, it is interpreted as a number representation of a date/time object, returning undesired results.

Note On UNIX, there is a switch that provides fast date-time parsing. If you have enabled this switch, you must refer to dates in expressions in the following order: month, day, and year. For example:

<CFIF "11/23/1998" GT "11/15/1998">

If this 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.

The Fast Date/Time Parsing switch is set on the ColdFusion Administrator Server Settings page. Please refer to Administering ColdFusion Server for more information about ColdFusion settings.

Examples

<!--- This example shows the various types of output
possible 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 a number of 
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>       



1