Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

Year

Year(dDate) -> nYear

Extracts the numeric year from a date.

YearAdvPL
01 · OVERVIEW

Overview

Year takes a date and returns its four-digit year independently of SET DATE/SET CENTURY. An empty date returns zero. Converting an invalid string and assuming a valid year are different steps: validate type and origin. The community example uses Date(); this fixed-date adaptation makes the expectation independent of the clock. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

Year(dDate) -> nYear

Parameters

dDate
DateRequired

Reference date.

Return value

Numeric; year, or zero for an empty date.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed734()
    Local dReference := StoD("20261028")
    // YYYYMMDD avoids depending on regional display formatting.
    ConOut(Year(dReference))
Return Nil
Expected result

Expected numeric result: 2026. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Year does not format dates or validate fiscal periods. Handle empty dates explicitly.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Year. Accessed on 2026-10-28.
  2. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_548_Funcao_Year.prw. Arquivo completo analisado; adaptação editorial. Accessed on 2026-10-28.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha