Formats
a date value using U.S. date formats. For international date support,
use LSDateFormat.
A text string representing the date formatted according to the mask. If no mask is specified, returns the value in dd-mmm-yy format.
DateFormat("date" [, "mask" ])
Now, CreateDate, LSDateFormat, LSParseDateTime, LSTimeFormat, TimeFormat, ParseDateTime
ColdFusion
MX: Added support for the following mask parameter
options: short, medium, long,
and full.
Parameter |
Description |
|---|---|
|
Date/time object, in the range 100 AD–9999 AD. |
|
Characters that show how ColdFusion displays a date:
|
When passing a date/time object as a string, enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object.
CreateDate function or Now function as the date parameter
of this function; for example: #DateFormat(CreateDate(2001, 3, 3))#Date
and time values in database query results can vary in sequence and formatting
unless you use functions to format them. To ensure that application users
correctly understand displayed dates and times, Adobe recommends
that you use this function and the LSDateFormat, TimeFormat, and LSTimeFormat functions to
format resultset values. For more information and examples, see
TechNote, "ColdFusion Server (5 and 4.5.x) with Oracle: Formatting Date and Time Query Results,"
on the website at go.adobe.com/kb/ts_tn_18070_en-us.
DateFormat function is best
used for formatting output, not for formatting input. For formatting
input, use one of the date/time creation functions (for example, CreateDate) instead.<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, "short")#
<li>#DateFormat(todayDate, "medium")#
<li>#DateFormat(todayDate, "long")#
<li>#DateFormat(todayDate, "full")#
</ul>
</cfoutput>