Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-30-2022 12:04 AM
I have two questions about date conversion in cypher.
First,
There is SQL in Oracle :
SELECT TO_CHAR(SYSDATE, 'D') FROM DUAL;
The SQL returns a number from 1 (sun) to 7 (sat)
Does Neo4j have a cypher function to replace it?
Second
If the arguemnts is put 1 (sun) ~ 7 (sat) as below SQL to return the NEXT day of the week in Oracle
SELECT NEXT_DAY(SYSDATE, 1) FROM DUAL
Is there a cypher query to replace it?
Thank you.
Solved! Go to Solution.
03-30-2022 09:14 AM
Oops, the above formula for transforming the day of the week is incorrect, as Saturday gets mapped to '0', so ignore this suggestion.
If this is needed, the simplest method I can think of is a literal mapping.
with [0,2,3,4,5,6,7,1] as weekDayMapping, date().dayOfWeek as day
return weekDayMapping[day]
03-30-2022 07:31 AM
Neo4j has a lot of support for date/time and duration entities. You can find a description in the following section of the cypher manual:
To address your two questions, the following should work:
return (date().dayOfWeek+1)%7
return date()+duration({days:1})
Review the manual for see all of the capabilities. There are many.
03-30-2022 08:42 PM
In the second case, I created the query as shown below with your information and hints.
WITH date.truncate('week', date(), {dayOfWeek: 1}) as outday,
date() as today
RETURN
CASE
WHEN outday < today then outday + duration({days:7})
ELSE outday
END AS thedate
Thank you.
03-30-2022 09:14 AM
Oops, the above formula for transforming the day of the week is incorrect, as Saturday gets mapped to '0', so ignore this suggestion.
If this is needed, the simplest method I can think of is a literal mapping.
with [0,2,3,4,5,6,7,1] as weekDayMapping, date().dayOfWeek as day
return weekDayMapping[day]
03-30-2022 07:58 PM
Thank you for your solution.
All the sessions of the conference are now available online