YEARS Function (LibreOffice Calc)
The YEARS function returns the number of whole years between two dates. It is essential for age calculations, contract durations, HR logic, amortization schedules, and any workflow requiring precise year-based differences.
Compatibility
▾| Excel | ✖ |
| Gnumeric | ✔ |
| Google_sheets | ✖ |
| Libreoffice | ✔ |
| Numbers | ✖ |
| Onlyoffice | ✔ |
| Openoffice | ✖ |
| Wps | ✔ |
| Zoho | ✔ |
What the YEARS Function Does ▾
- Returns the whole number of years between two dates
- Accepts dates, datetimes, and serial numbers
- Can return positive or negative values
- Ignores partial years (no rounding)
It is designed to be precise, predictable, and ideal for year‑interval calculations.
Syntax ▾
YEARS(start_date; end_date; [mode])
Arguments
-
start_date:
The beginning date. -
end_date:
The ending date. -
mode (optional):
0(default): Count whole years only1: Count partial years as whole years (ceiling behavior)
Basic Examples ▾
Whole years between two dates
=YEARS("2000-01-01"; "2024-01-01")
Returns 24.
Years between dates with partial year ignored
=YEARS("2000-06-15"; "2024-04-10")
Returns 23.
Years between dates counting partial years
=YEARS("2000-06-15"; "2024-04-10"; 1)
Returns 24.
Using cell references
=YEARS(A1; B1)
Advanced Examples ▾
Age in whole years
=YEARS(A1; TODAY())
Years between two text dates
=YEARS(DATEVALUE(A1); DATEVALUE(B1))
Years between imported CSV timestamps
=YEARS(DATEVALUE(LEFT(A1;10)); DATEVALUE(LEFT(B1;10)))
Years between Excel serial dates stored as text
=YEARS(DATE(1899;12;30)+VALUE(A1); DATE(1899;12;30)+VALUE(B1))
Determine if a contract is older than 5 years
=YEARS(A1; TODAY()) >= 5
Determine if two dates fall in the same year
=YEARS(A1; B1) = 0
Calculate years remaining until retirement
=YEARS(TODAY(); A1)
Calculate service duration in years
=YEARS(HireDate; TODAY())
Edge Cases and Behavior Details ▾
YEARS returns an integer
Accepts:
- Real dates
- Serial numbers
- DATEVALUE outputs
- ISO date strings
Invalid text → Err:502
Behavior details
- Partial years are ignored unless mode = 1
- Negative results allowed
- Time components are ignored
- Date order matters
YEARS of an error → error propagates
Common Errors and Fixes ▾
Err:502 — Invalid argument
Cause:
- Text not recognized as a date
- Non-numeric values
- Wrong separators
Fix:
- Wrap with DATEVALUE
- Clean text with TRIM or SUBSTITUTE
Wrong year count due to partial year
Fix:
- Use mode = 1 to count partial years
Unexpected result from serial numbers
Cause:
- Imported values represent days since epoch
Fix:
- Convert with DATE(1899;12;30)+VALUE(A1)
Best Practices ▾
- Use YEARS for age, service duration, and contract logic
- Normalize text dates with DATEVALUE
- Use mode = 1 when partial years should count
- Use YEARS with YEARFRAC for precise fractional calculations
- Use YEARS for annualized reporting periods
YEARS is your year‑interval engine — perfect for age calculations, contract durations, HR logic, and any workflow where year‑based differences matter.
Related Patterns and Alternatives ▾
- Use MONTHS for month intervals
- Use DATEDIF for more granular intervals
- Use YEARFRAC for fractional years
- Use YEAR for extracting the year
- Use DATEVALUE for text conversion
By mastering YEARS and its companion functions, you can build powerful, reliable, and fully structured year‑interval workflows in LibreOffice Calc.