apoc.date.toYears

Details

Syntax

apoc.date.toYears(value [, format ])

Description

Converts the given timestamp or the given date into a FLOAT representing years.

Arguments

Name

Type

Description

value

ANY

The timestamp or datetime string to extract the years from.

format

STRING

The format the given datetime string is in. The default is: yyyy-MM-dd HH:mm:ss.

Returns

FLOAT

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;
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;
Results
years

2020.027397260274