cancel
Showing results for 
Search instead for 
Did you mean: 

Months in the JS date object and the cypher date function are offset by 1

IamFlowZ
Node

Hello weary traveler!
If you made it here, you have run into a terrible issue to have! Particularly considering it's an issue that only happens a handful of times in a given calendar year!

As of writing this, today is July 31st. June only has 30 days. I found this morning that all of my queries that used the "date()" function began to fail. In production. Upon examination of the arguments to those queries I pass an object simliar to this

const now = new Date()
some stuff...
{
  year: now.getYear(),
  month: now.getMonth(),
  day: now.getDay()
}

An issue with this arises, because the "date()" cypher function expects the month argument to be 1 based, however the javascript date object has a month property that is 0 based. So the simple fix for this is

const now = new Date()
some stuff...
{
  year: now.getYear(),
  month: now.getMonth() + 1,
  day: now.getDay()
}

I hope this helps anyone else who happens to run into this issue

0 REPLIES 0