Official Content

Adds a given number of years to a given date.


AddYr(date-expression | datetime-expression , numeric-expression)


date-expression | datetime-expression 
    Given date or datetime.

    The number of years added to the date-expression | datetime-expression.

Type returned:
Date | DateTime


Objects: Procedure, Transaction, Web Panel Panel, Data Provider
Generators: .NET, .NET Framework, JavaApple, Android, Angular


Returns a value which results from adding numeric-expression years to date-expression or datetime-expression. When the type assigned is date, it returns a date value and when the type assigned is datetime, it returns a datetime.


Date1 = CtoD('29/02/2008')
Date2 = AddYr(Date1, 1)
// Result: Date2 = 28/02/2009 if Date2 is a date type attribute
Date3 = AddYr(Date1,-1)
// Result: Date3 = 28/02/2007 if Date3 is a date type attribute
Date4 = AddYr(Today(), 1)    //Today() = 18/12/2008
// Result: Date4 = 18/12/2009 00:00:00 if Date4 is a datetime type attribute
Date5 = AddYr(Now(), -2)   //Now() = 12/06/2008 10:30:00
// Result: Date5 = 12/06/2006 if Date5 is a date type attribute
// Result: Date5 = 12/06/2006 10:30:00 if Date5 is a datetime type attribute

See Also

AddMth function
AddDays method

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant