The number of years between datetimes.
Years = SRP_DateTime("YearSpan", FromDateTime, ToDateTime, Fractional)
Returns
The number of years between two datetimes
Parameters
Parameter | Description |
---|---|
FromDateTime | A starting datetime in OI internal format. (REQUIRED) |
ToDateTime | An ending datetime 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 datetimes. The result will be positive if the starting datetime comes before the ending datetime and negative if the ending datetime comes first.
If Fractional is set to 1, which is the default, you will get a decimal number if the month, day, or time of day are not the same for each datetime. If you want whole years only, set Fractional to 0.
Leap years make calculating a fraction of a year interesting. If the month, day, and time of day are the same between datetimes, then you will get a whole year. For example, the span between February 28, 2020 and February 28, 2021 is 1.0 as will 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, day, or time of day are different, then the fraction is based on the number of seconds 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 datetimes From = SRP_DateTime("Parse", "Monday, December 8, 1941 at 7:51:43am", "DDD, MMMM D, YYYY at h:mm:sstt") To = SRP_DateTime("Parse", "Thursday, March 30, 1978 at 12:41:08pm", "DDD, MMMM D, YYYY at h:mm:sstt") Years = SRP_DateTime("YearSpan", From, To) // Get the number of whole years Years = SRP_DateTime("YearSpan", From, To, 0)