datePart
Description
Extracts a part from a date value.
Categories
Related
History
ColdFusion
MX 6.1: Added the datepart character L or l to represent
milliseconds.
Syntax
DatePart("datepart", "date")
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| date | Date/time object, in the range 100 AD–9999 AD. | ||
| datepart | String: yyyy: Year q: Quarter m: Month y: Day of year d: Day w: Weekday ww: Week h: Hour n: Minute s: Second l: Millisecond |
Returns
Part
of a date, as an integer.
Usage
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.
Example
<!--- This example shows information available from DatePart --->
<cfset todayDate = Now()>
<h3>DatePart Example</h3>
Today's date is <cfoutput>#todayDate#</cfoutput>.
Using datepart, we extract an integer representing the dateparts from that value
<cfoutput>
<ul>
<li>year: #DatePart("yyyy", todayDate)#</li>
<li>quarter: #DatePart("q", todayDate)#</li>
<li>month: #DatePart("m", todayDate)#</li>
<li>day of year: #DatePart("y", todayDate)#</li>
<li>day: #DatePart("d", todayDate)#</li>
<li>weekday: #DatePart("w", todayDate)#</li>
<li>week: #DatePart("ww", todayDate)#</li>
<li>hour: #DatePart("h", todayDate)#</li>
<li>minute: #DatePart("n", todayDate)#</li>
<li>second: #DatePart("s", todayDate)#</li>
</ul>
</cfoutput>