Choose where you’d like to start

totalYears()

Overview

The totalYears() function takes startDateTimeValue and endDateTimeValue as arguments. It returns the number of years between the given date-time values.

Note: The difference between yearsBetween function and totalYears function is that the yearsBetween function considers a year as 365 days.

For example, let's say the start date is specified as 02-Jan-2020 and the end date is specified as 01-Jan-2021. The year 2020 is a leap year and hence it contains 366 days. In this case, the yearsBetween function returns 1 and the totalYears function returns 0. This is because the yearsBetween function considers that a year always contains 365 days whereas the totalYears function also takes leap years into consideration.

Return Type

  • Number

Syntax

<variable> = <startDateTimeValue>.totalYears(<endDateTimeValue>);

(OR)

<variable> = totalYears(<startDateTimeValue>,<endDateTimeValue>);
ParameterData typeDescription
<variable>NUMBERVariable which will contain the returned number.
<startDateTimeValue>DATE TIME

The starting date-time value.

<endDateTimeValue>DATE TIME

The ending date-time value.

A runtime error will be encountered if:

  • the date value exceeds the number of days in that month.
  • an incorrect month value is specified.
  • the year value has more than 4 digits.
  • Please refer this help document to learn about the supported date-time formats.

Examples

startDate = '1-Jan-2019'; 
endDate = '31-Dec-2019'; 
newStartDate = '1-Jan-2019'; 
newEndDate = '1-Jan-2020'; 
numberOfYears = totalYears(startDate,endDate);     // returns 0 
numOfYears = totalYears(newStartDate,newEndDate);  // returns 1

Get Started Now

Execute