I am trying to calculate a date as 18 calendar months after a reference date.
This is what I am currently doing as a stopgap but I am hoping that there is a better way to resolve this as ideally I would love to just add calendar months to the reference date so that the following endDate
resolves to 2025-02-21
instead of 2025-02-18
.
WITH apoc.date.parse("2023-08-21 17:48", "ms", "yyyy-MM-dd HH:mm") as refDatetime, apoc.date.add(refDatetime, "ms", 547, "days") as endDatetime
return apoc.date.format(refDatetime, "ms", "yyyy-MM-dd") as refDate, apoc.date.format(endDatetime, "ms", "yyy-MM-dd") as endDate
Returns:
refDate | endDate |
---|---|
2023-08-21 | 2025-02-18 |
Notes:
- Since the
apoc.date.add(...)
method doesn't support "adding" months, I'm using days (30.437 average days/month * 18 months = 547.8 ish, and then rounding it down).
DBMS info:
- Version: 5.19.0
- Edition: community
- Plugins: apoc
I realize I can just write some sort of script to calculate these values but I wanted to check in with the community first to see if this is even possible using just cypher.
Thanks in advance!