datePart

Extracts a part from a datetime value as a numeric.

datePart(datepart, date) → returns Numeric

Member Function Syntax

date.datePart(datepart)

datePart Argument Reference

datepart
Required

yyyy: Year
q: Quarter
m: Month
y: Day of year
d: Day
w: Weekday
ww: Week
h: Hour
n: Minute
s: Second
l: Millisecond Values:
  • yyyy
  • q
  • m
  • y
  • d
  • w
  • ww
  • h
  • n
  • s
  • l

date
Required

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