1

I have nodes with person label where i am storing their date of births too. For e.g.:

Person
{
  name: Tim
  D.O.B: 01/23/1990
}

Now I need to calculate his age as of current date and time ( i.e. either 27 years or 27 years, 10 months, 18 days ). So, could anyone let me know how could I perform it?

P.S.: I tried the following but seems to be missing something here :

WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate,
     apoc.date.format(timestamp(),'y','MM/dd/yyyy') as endDate,
     apoc.date.parse(endDate,'y','MM/dd/yyyy') as ed

 RETURN ed - 4
4

2 回答 2

3

APOC 日期格式/解析/添加/转换函数支持的单位是:ms,s,m,h,d and their long forms. 要使用月份,您需要使用特定的日历系统,并且没有通用的月份时间单位来进行转换或添加,因为不同的月份由不同的日子组成(然后是 2 月的闰日)。

多年来,您将不得不使用日单位并使用除以 365。

这是一个查询,可以让您以年和日为单位变老。

WITH apoc.date.parse('01/23/1990', 'd', 'MM/DD/yyyy') as birth, apoc.date.convert(timestamp(), 'ms', 'd') as now
WITH now - birth as daysAlive
RETURN daysAlive / 365 as yearsAlive, daysAlive % 365 as daysExtra

如果您想进入月份,最好使用 MM/DD/yyyy 表示中的月份/年份字段并在这些字段上提取一些数学。我会看看我们可以在 APOC 中提供哪些支持。

于 2017-12-11T11:21:36.693 回答
0

有些喜欢

WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate
RETURN apoc.date.convert(timestamp() - startDate,"ms","d");

也许 ?

希望这可以帮助。

问候,汤姆

于 2017-12-11T10:52:11.133 回答