How to format a date value using U.S. date format in ColdFusion

DateFormat() - format a date value using U.S. date format

DateFormat.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DateFormat function example: how to format a date value using U.S. date format</title>
</head>

<body>
<h2 style="color:hotpink">DateFormat Function Example</h2>

<cfset MyDate=Now()>

<cfoutput>
<b>
MyDate: #MyDate#
<br /><br />
</b>
</cfoutput>
<table style="color:LightGreen; background:Green;" border="1" bordercolor="DarkGreen">
    <tr>
     <td style="font-weight:bold">DateFormat</td>
     <td style="font-weight:bold"></td>
     <td style="font-weight:bold">Output</td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"d")#</td>
     <td>Day</td>
     <td><cfoutput>#DateFormat(MyDate,"d")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"dd")#</td>
     <td>Day</td>
     <td><cfoutput>#DateFormat(MyDate,"dd")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"ddd")#</td>
     <td>Day</td>
     <td><cfoutput>#DateFormat(MyDate,"ddd")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"dddd")#</td>
     <td>Day</td>
     <td><cfoutput>#DateFormat(MyDate,"ddddd")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"m")#</td>
     <td>Month</td>
     <td><cfoutput>#DateFormat(MyDate,"m")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"mm")#</td>
     <td>Month</td>
     <td><cfoutput>#DateFormat(MyDate,"mm")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"mmm")#</td>
     <td>Month</td>
     <td><cfoutput>#DateFormat(MyDate,"mmm")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"mmm")#</td>
     <td>Month</td>
     <td><cfoutput>#DateFormat(MyDate,"mmmm")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"yy")#</td>
     <td>Year</td>
     <td><cfoutput>#DateFormat(MyDate,"yy")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"yyyy")#</td>
     <td>Year</td>
     <td><cfoutput>#DateFormat(MyDate,"yyyy")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"short")#</td>
     <td>Short</td>
     <td><cfoutput>#DateFormat(MyDate,"short")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"medium")#</td>
     <td>Medium</td>
     <td><cfoutput>#DateFormat(MyDate,"medium")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"full")#</td>
     <td>Full</td>
     <td><cfoutput>#DateFormat(MyDate,"full")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"gg")#</td>
     <td></td>
     <td><cfoutput>#DateFormat(MyDate,"gg")#</cfoutput></td>
    </tr>
    <tr>
     <td>#DateFormat(MyDate,"dd-mm-yy")#</td>
     <td></td>
     <td><cfoutput>#DateFormat(MyDate,"mmm-ddd-yy")#</cfoutput></td>
    </tr>
</table>

</body>
</html>





More ColdFusion examples