DatePart() - get a part from a date value
DatePart.cfm
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DatePart function example: how to get a part from a date value</title>
</head>
<body>
<h2 style="color:hotpink">DatePart 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">DatePart</td>
<td style="font-weight:bold"></td>
<td style="font-weight:bold">Output</td>
</tr>
<tr>
<td>#DatePart("yyyy",MyDate)#</td>
<td>Years</td>
<td><cfoutput>#DatePart("yyyy",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("q",MyDate)#</td>
<td>Quarter</td>
<td><cfoutput>#DatePart("q",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("m",MyDate)#</td>
<td>Month</td>
<td><cfoutput>#DatePart("m",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("y",MyDate)#</td>
<td>Day of Year</td>
<td><cfoutput>#DatePart("y",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("w",MyDate)#</td>
<td>Weekday</td>
<td><cfoutput>#DatePart("w",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("ww",MyDate)#</td>
<td>Week</td>
<td><cfoutput>#DatePart("ww",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("yyyy",MyDate)#</td>
<td>Years</td>
<td><cfoutput>#DatePart("yyyy",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("h",MyDate)#</td>
<td>Hour</td>
<td><cfoutput>#DatePart("h",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("n",MyDate)#</td>
<td>Minute</td>
<td><cfoutput>#DatePart("n",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("s",MyDate)#</td>
<td>Second</td>
<td><cfoutput>#DatePart("s",MyDate)#</cfoutput></td>
</tr>
<tr>
<td>#DatePart("l",MyDate)#</td>
<td>Millisecond</td>
<td><cfoutput>#DatePart("l",MyDate)#</cfoutput></td>
</tr>
</table>
</body>
</html>