Year

Description

From a date/time object, gets the year value.

Return value

The year value of date.

Category

Date and time functions

Syntax

Year(date) 

See also

DatePart, IsLeapYear

Parameters

Parameter Description
date
A date/time object in the range 100 AD-9999 AD. See "How ColdFusion processes two-digit year values".

Usage

When passing a date as a string, enclose it in quotation marks. Otherwise, it is interpreted as a number representation of a date.

Example

<h3>Year Example</h3>
<cfif IsDefined("FORM.year")>
  More information about your date:
  <cfset yourDate = CreateDate(FORM.year,FORM.month,FORM.day)>
  <cfoutput>
  <p>Your date, #DateFormat(yourDate)#.
  <br>It is #DayofWeekAsString(DayOfWeek(yourDate))#, 
day #DayOfWeek(yourDate)# in the week.
  <br>This is day #Day(yourDate)# 
in the month of #MonthAsString(Month(yourDate))#, 
which has #DaysInMonth(yourDate)# days.
  <br>We are in week #Week(yourDate)# of #Year(YourDate)# 
(day #DayofYear(yourDate)# of #DaysinYear(yourDate)#). <br>
  <cfif IsLeapYear(Year(yourDate))>
    This is a leap year
    <cfelse>This is not a leap year
  </cfif>
  </cfoutput>
</cfif>

Comments