Choose where you’d like to start

yearFraction

Overview

The yearFraction function returns a period of time that two date values specify, in decimal format. In other words, the number of days between two dates is divided by the total number of days in a year, 365, to obtain the year fraction as a decimal value.

Return Type

Usecase

Let's say you are running a financial institution that provides your customers with personal loans. A customer wants to calculate the extent to which their loan's interest will reduce after they make a part payment. To calculate this, the fraction of years from the date they make the part payment until the end of their tenure has to be determined. The yearFraction function can be used here and the revised interest rates can be further calculated.

See how this can be implemented

Syntax  

<variable> = <date1>.yearFraction(<date2>);

where:

ParameterData TypeDescription
<variable>DECIMALVariable which will contain the returned value.
<date1>DATE-TIMEThe starting date-time/date value.
Note
  • When the start date is higher than the end date, the yearFraction function will nevertheless run, returning a negative value.
<date2>DATE-TIMEThe ending date-time/date value.

Note

  • When the DATE-TIME data type is used, the difference in time stamp, if provided, will also be considered while returning the year fraction value. If no time stamp is included, 00:00:00 will be considered by default.

Examples

date1 = '17-Jan-2019';
date2 = '29-Jan-2019';
yf = date1.yearFraction(date2);
info yf;                                                           // returns 0.03287671232876712
date3 = '24-Jun-1997';
date4 = '24-Mar-2001 10:10:37';
yearfractionvalue = date3.yearFraction(date4);
info yearfractionvalue;                                            // returns 3.7519608384069003

Usecase Implementation

Say you've created a Payment Management application using Zoho Creator, for your financial institution. A customer enters the following details in the Part Payment Calculation form:

  • Loan ID - ****21
  • Date on which they want to make a part payment - 03-Apr-2020
  • Tenure Closure Date - 25-May-2035

To calculate the reduction in interest rate, the year fraction value has to be found. This can be found by dividing the number of days between the part payment date and tenure closure date by the total number of days in a year. A workflow with the following Deluge script will help you do this.

partpaymentdate = '03-Apr-2020';
enddate = '25-May-2035';
yfvalue = partpaymentdate.yearFraction(enddate);
info yfvalue;                                              // returns decimal value 15.150684931506849

where:

partpaymentdate
DATE-TIME variable that denotes the date value on which the part payment was made
enddate
DATE-TIME variable that denotes the date value on which the tenure ends.
yfvalue
TEXT variable that returns the year fraction value as a decimal.

Using this year fraction value, your financial institution can readjust the EMI for the customer.

Related Links

Get Started Now

Execute