Home Cooker Classes Others Rice CookerGX
Classes  >  datetime  >  AddYears(int)
datetime class : AddYears(int) method

Description

Gets the new datetime instance which is obtained by adding the number of years to the invoker instance.

Syntax

datetimeInstance.AddYears(int numberOfYears)

Arguments

ClassNameDescription
intnumberOfYearsNumber of years

Return value

ClassDescription
datetimeNew datetime type instance which is obtained by adding the argument.

Sample code

datetime dt = new datetime(2016, 3, 4, 4, 13, 0);

datetime addYear1 = dt.AddYears(5);//2021/03/04 4:13:00

datetime addYear2 = dt.AddYears(-5);//2011/03/04 4:13:00

Notes

It's a wrapper of the System.DateTime.AddYears(Int32).

Links for reference

Copyright © Rice All rights reserved.