curatedapi
Browse the docs

Guides

Finance

Excel functions

Late payments

E-invoices

Accounting

Number checks

VAT and GST

Billing and pricing

Money and currencies

Dates and time

Math

Unit conversion

Everyday

Health

Excel YEARFRAC function: fraction of a year between dates API

The fraction of a year between two dates under Excel's five day-count bases, including Excel's own actual/actual rule.

POST https://api.curatedapi.com/v1/calc/excel/yearfrac

YEARFRAC(start_date, end_date, [basis]). Basis 1 follows Excel exactly: within a year it divides by 365 or 366 (366 when the span includes 29 February); over longer spans it divides by the average length of the calendar years touched. Basis 0 treats the last day of February as the 30th. The order of the dates does not matter.

Formula

days (by basis) ÷ year length (by basis)
  • Arguments are named and ordered as in Excel. Excel computes in binary floating point; this API computes the exact value of the same formula and rounds it once, so it agrees with Excel to the digits Excel can show, and where Excel's own rounding error reaches the 15th digit this answer is the correct one.
  • Dates are ISO 8601 (YYYY-MM-DD) from 1900-03-01 to 9999-12-31, so Excel's fictional 29 February 1900 never comes into play. Each date result also gives Excel's serial number (1900 date system).

Inputs

Send numbers as strings to keep every digit. options sets precision and rounding (see numbers and rounding).

InputTypeDescription
start_date required date (YYYY-MM-DD) Start date.
end_date required date (YYYY-MM-DD) End date.
basis integer
default 0
Day count basis: 0 US (NASD) 30/360; 1 Actual/actual; 2 Actual/360; 3 Actual/365; 4 European 30/360. Allowed: >= 0 and <= 4.
options.rounding half_even | half_up | half_down | up | down | ceiling | floor Rounding mode applied once to each result. Default half_even.
options.decimals integer Round results to this many digits after the decimal point.
options.significant_digits integer Round results to this many significant digits.

Result

Under result in the answer, next to exactness, precision, inputs, formula, references and warnings.

ResultTypeDescription
yearfracdecimal (string)Fraction of a year.

Examples

Microsoft's example: 2012, US 30/360

Requestcurl
curl https://api.curatedapi.com/v1/calc/excel/yearfrac \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "options": {"decimals": 8}
  }'
200 OKResponse
{
  "calculator": "excel/yearfrac@1",
  "result": {
    "yearfrac": "0.58055556"
  },
  "exactness": {
    "yearfrac": "rounded"
  },
  "precision": {
    "rounding": "half_even",
    "decimals": 8
  },
  "inputs": {
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "basis": 0
  },
  "formula": "days (by basis) ÷ year length (by basis)",
  "references": [
    {
      "title": "Microsoft Excel YEARFRAC function",
      "url": "https://support.microsoft.com/en-us/excel/functions/yearfrac-function"
    },
    {
      "title": "OpenDocument formula specification (ODF 1.2 part 2), section 4.11.7, which documents Excel's day-count rules",
      "url": "https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html"
    }
  ],
  "warnings": []
}

Microsoft's example: 2012, actual/actual

Requestcurl
curl https://api.curatedapi.com/v1/calc/excel/yearfrac \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "basis": 1,
    "options": {"decimals": 8}
  }'
200 OKResponse
{
  "calculator": "excel/yearfrac@1",
  "result": {
    "yearfrac": "0.57650273"
  },
  "exactness": {
    "yearfrac": "rounded"
  },
  "precision": {
    "rounding": "half_even",
    "decimals": 8
  },
  "inputs": {
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "basis": 1
  },
  "formula": "days (by basis) ÷ year length (by basis)",
  "references": [
    {
      "title": "Microsoft Excel YEARFRAC function",
      "url": "https://support.microsoft.com/en-us/excel/functions/yearfrac-function"
    },
    {
      "title": "OpenDocument formula specification (ODF 1.2 part 2), section 4.11.7, which documents Excel's day-count rules",
      "url": "https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html"
    }
  ],
  "warnings": []
}

Microsoft's example: 2012, actual/365

Requestcurl
curl https://api.curatedapi.com/v1/calc/excel/yearfrac \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "basis": 3,
    "options": {"decimals": 8}
  }'
200 OKResponse
{
  "calculator": "excel/yearfrac@1",
  "result": {
    "yearfrac": "0.57808219"
  },
  "exactness": {
    "yearfrac": "rounded"
  },
  "precision": {
    "rounding": "half_even",
    "decimals": 8
  },
  "inputs": {
    "start_date": "2012-01-01",
    "end_date": "2012-07-30",
    "basis": 3
  },
  "formula": "days (by basis) ÷ year length (by basis)",
  "references": [
    {
      "title": "Microsoft Excel YEARFRAC function",
      "url": "https://support.microsoft.com/en-us/excel/functions/yearfrac-function"
    },
    {
      "title": "OpenDocument formula specification (ODF 1.2 part 2), section 4.11.7, which documents Excel's day-count rules",
      "url": "https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html"
    }
  ],
  "warnings": []
}

References

Results follow each calculator's documented rules and the sources listed. They are not financial, tax or legal advice. Check that the rules fit your case before you rely on a result. See the terms.

Errors share one format; see errors. Billing, retries and batches work the same for every endpoint.