The number of years between dates.

Years = SRP_Date("YearSpan", FromDate, ToDate, Fractional)

## Returns

The number of years between two dates

## Parameters

Parameter | Description |
---|---|

FromDate | A starting date in OI internal format. (REQUIRED) |

ToDate | An ending date in OI internal format. (REQUIRED) |

Fractional | Determines if the span should be in whole years or fractional years. (OPTIONAL) |

## Remarks

The "YearSpan" service calculates the number of years between two dates. The result will be positive if the starting date comes before the ending date and negative if the ending date comes first.

If Fractional is set to 1, which is the default, you will get a decimal number if the month or day are not the same for each date. If you want whole years only, set Fractional to 0.

Leap years make calculating a fraction of a year interesting. If the month and day are the same between dates, then you will get a whole year. For example, the span between February 28, 2020 and February 28, 2021 is 1.0 as is the span between February 28, 2021 and February 28, 2022, even though there are 366 days between the first pair and 365 days between the second. If the month or day are different, then the fraction is based on the number of days in the earlier datetime's year. For example, February 28, 2020 to January 30, 2021 will return 0.920765027322404, but February 28, 2020 to January 30, 2021 will return 0.920547945205479. That's because the first range comes to 337 days out of 366 and the second range is 336 days out of 365. Thus, fractional years should be treated as an approximate fractional span given the nature of leap years.

## Examples

// Get the number of years between two dates From = SRP_Date("Parse", "Monday, December 8, 1941", "DDD, MMMM D, YYYY") To = SRP_Date("Parse", "Thursday, March 30, 1978", "DDD, MMMM D, YYYY") Years = SRP_Date("YearSpan", From, To) // Get the number of whole years Years = SRP_Date("YearSpan", From, To, 0)