apoc.date.toYears

Function APOC Core

toYears(timestamp) or toYears(date[,format]) converts timestamp into floating point years

Signature

apoc.date.toYears(value :: ANY?, format = yyyy-MM-dd HH:mm:ss :: STRING?) :: (FLOAT?)

Input parameters

Name Type Default

value

ANY?

null

format

STRING?

yyyy-MM-dd HH:mm:ss

Usage Examples

The following converts a datetime in milliseconds to floating point years:

WITH datetime("2020-11-05").epochMillis AS datetime
RETURN apoc.date.toYears(datetime) AS years;
Table 1. Results
years

50.87945205479452

The following converts a date to floating point years:

RETURN apoc.date.toYears("2020-11-02", "YYYY-MM-dd") AS years;
Table 2. Results
years

2020.027397260274