Adds years to a datetime.

DateTime = SRP_DateTime("AddYears", Datetime, Years)

Returns

A new datetime.

Parameters

ParameterDescription
DatetimeA datetime in OI internal format. (REQUIRED)
YearsThe number of years to add. (REQUIRED)

Remarks

The "AddYears" service calculates a new datetime by adding the given number of years to an existing datetime. You can pass whole numbers or decimal numbers. You can also pass negative values to subtract years.

This service does not simply add years in chunks of 365. It adds whole years without modifying the month, day, and time of day if possible. January 30, 2020 falls on a leap year, but adding 1 whole year still gets you January 30, 2021. If adding a whole year would make the date invalid, the date will be adjusted. Adding 1 whole year to February 29, 2020 will get you February 28, 2021. Fractions of a year are calculated using the average year length, which is 365.25.

Examples

// Add 10 years to the current datetime
NewDateTime = SRP_DateTime("AddYears", DateTime(), 10)

// Add a year and a half to the current datetime
NewDateTime = SRP_DateTime("AddYears", DateTime(), 1.5)

// Subtract 10 years from the current datetime
NewDateTime = SRP_DateTime("AddYears", DateTime(), -10)

  • No labels