DatePart

Description

Returns part of a date as an integer.

Category

Date and time functions

Syntax

DatePart(datepart, date) 

See also

DateAdd, DateConvert

Parameters

Parameter
Description
datepart
One of the following strings:
  • yyyy    Year
  • q    Quarter
  • m    Month
  • y    Day of year
  • d    Day
  • w    Weekday
  • ww    Week
  • h    Hour
  • n    Minute
  • s    Second
date
A date/time object

Usage

Year values 0 - 29 are interpreted as 21st century dates. Year values 30 - 99 are interpreted as 20th century dates.

When passing a date/time value as a string, enclose it in quotes. Otherwise, it is interpreted as a number representation of a date/time object.

Example

<!--- This example shows information available from DatePart --->
<html>
<head>
<title>DatePart Example</title>
</head>

<cfset todayDate = Now()>
<body>
<H3>DatePart Example</H3>

<P>Today's date is <cfoutput>#todayDate#</cfoutput>.

<P>Using datepart, we can extract an integer representing the dateparts from that value
<cfoutput>
<UL>
  <LI>year: #DatePart("yyyy", todayDate)#
  <LI>quarter: #DatePart("q", todayDate)#
  <LI>month: #DatePart("m", todayDate)#
  <LI>day of year: #DatePart("y", todayDate)#
  <LI>day: #DatePart("d", todayDate)#
  <LI>weekday: #DatePart("w", todayDate)#
  <LI>week: #DatePart("ww", todayDate)#
  <LI>hour: #DatePart("h", todayDate)#
  <LI>minute: #DatePart("n", todayDate)#
  <LI>second: #DatePart("s", todayDate)#
</UL>  
</cfoutput>  

</body>
</html>