Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : YEAR function
 

YEAR function

Evaluates a date expression and returns the year value of that date, including the century, as an INTEGER value.

Syntax

YEAR ( date )
YEAR ( datetime-expression )
date
A date expression for which you want to determine the year.
datetime-expression
An expression that evaluates to a DATETIME or DATETIME-TZ. The YEAR function returns the year of the date part of the DATETIME or DATETIME-TZ value.

Example

This procedure uses the YEAR function to determine if an Order date is in this century or the next, and then uses a different display format for each:
r-year.p
DEFINE VARIABLE outfmt  AS CHARACTER NO-UNDO.
DEFINE VARIABLE orddate AS CHARACTER NO-UNDO
  LABEL "Order Date" FORMAT "x(10)".

FOR EACH Order NO-LOCK:
  ASSIGN
    outfmt  = IF YEAR(Order.OrderDate) >= 2000 THEN
                "99/99/9999" ELSE "99/99/99"
    orddate = STRING(Order.OrderDate, outfmt).

DISPLAY Order.OrderNum orddate Order.Terms.
END.

See also

ADD-INTERVAL function, DATE function, DATE-FORMAT attribute, DATETIME function, DATETIME-TZ function, DAY function, ETIME function, INTERVAL function, ISO-DATE function, MONTH function, MTIME function, NOW function, TIME function, TIME-SOURCE attribute, TIMEZONE function, TODAY function, YEAR-OFFSET attribute