YEAR( ) function

Extracts the year from a specified date or datetime and returns it as a numeric value using the YYYY format.

Syntax

YEAR(date/datetime)

Parameters

Name Type Description
date/datetime

datetime

The field, expression, or literal value to extract the year from.

Output

Numeric.

Examples

Basic examples

Returns 2014:

YEAR(`20141231`)
YEAR(`141231 235959`)

Returns the year for each value in the Invoice_date field:

YEAR(Invoice_date)

Remarks

Parameter details

A field specified for date/datetime can use any date or datetime format, as long as the field definition correctly defines the format.

Specifying a literal date or datetime value

When specifying a literal date or datetime value for date/datetime, you are restricted to the formats in the table below, and you must enclose the value in backquotes – for example, `20141231`.

Do not use any separators such as slashes (/) or colons (:) between the individual components of dates or times.

  • Datetime values – you can use any combination of the date, separator, and time formats listed in the table below. The date must precede the time, and you must use a separator between the two. Valid separators are a single blank space, the letter 't', or the letter 'T'.

  • Time values – you must specify times using the 24-hour clock. Offsets from Coordinated Universal Time (UTC) must be prefaced by a plus sign (+) or a minus sign (-).

    Example formats

    Example literal values

    YYYYMMDD

    `20141231`

    YYMMDD

    `141231`

    YYYYMMDD hhmmss

    `20141231 235959`

    YYMMDDthhmm

    `141231t2359`

    YYYYMMDDThh

    `20141231T23`

    YYYYMMDD hhmmss+/-hhmm

    (UTC offset)

    `20141231 235959-0500`

    YYMMDD hhmm+/-hh

    (UTC offset)

    `141231 2359+01`

    Note

    Do not use hh alone in the main time format with data that has a UTC offset. For example, avoid: hh+hhmm. Results can be unreliable.

     

ACL Scripting Guide 14.1