datePart

Extracts a part from a date value as a numeric.
[datepart - quicky]
yyyy: Year; q: Quarter; m: Month; y: Day of year; d: Day
w: Weekday; ww: Week; h: Hour; n: Minute; s: Second;
l: Millisecond

datePart(datepart, date) → returns Numeric

Member Function Syntax

date.datePart(datepart)

Argument Reference for the datePart function

datepart

Required: Yes
Values:
  • yyyy
  • q
  • m
  • y
  • d
  • w
  • ww
  • h
  • n
  • s
  • l

date

Required: Yes
Values:
  • now()

Compatibility

ColdFusion:

Member function is available is CF 11+.

Lucee:

Member function is available is Lucee 4.5+. The syntax for this member function is date.part(datepart).

Examples sample code invoking the datePart function


Tag Syntax

<!--- This example shows information available from datePart ---> 
 <cfset todayDate = now()> 
 <h3>datePart Example</h3> 
 <p>Today's date is <cfoutput>#todayDate#</cfoutput>. 
 <p>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>   

Fork me on GitHub