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:
Parameter  Data Type  Description 
<variable>  DECIMAL  Variable which will contain the returned value. 
<date1>  DATETIME  The starting datetime/date value. Note:

<date2>  DATETIME  The ending datetime/date value. 
Note:
 When the DATETIME 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 = '17Jan2019'; date2 = '29Jan2019'; yf = date1.yearFraction(date2); info yf; // returns 0.03287671232876712
date3 = '24Jun1997'; date4 = '24Mar2001 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  03Apr2020
 Tenure Closure Date  25May2035
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 = '03Apr2020'; enddate = '25May2035'; yfvalue = partpaymentdate.yearFraction(enddate); info yfvalue; // returns decimal value 15.150684931506849
where:
partpaymentdate
enddate
yfvalue
Using this year fraction value, your financial institution can readjust the EMI for the customer.