DateTime.addYear()
Signature
DateTime addYear (DateTime date, int years)
Description
Adds a number of years to a DateTime and returns the result. The input DateTime is not modified.
Parameters
Name | Type | Description |
date | DateTime | A DateTime to add some amount of time to. |
years | int | The number of years to add to the DateTime. |
Returns
Type | Description |
DateTime | A new DateTime that results from adding the number of time units to the date argument. |
Example
Date dateNow = Date.now ();
String start = DateTime.format (dateNow, "yyyy-MM-dd HH:mm:ss");
String result = DateTime.format (DateTime.addYear(dateNow, 1), "yyyy-MM-dd HH:mm:ss");
Result is:
start contains: "2004-03-11 14:59:04"
result contains: "2005-03-11 14:59:04"