The given date format in CSV is '(Fri) 09 Jan 2018 (32)'. This should feed to database as a date column to allow order by date. How could convert above format to Neo4j date format at the insertion time ?
Asked
Active
Viewed 148 times
2 Answers
1
Solution
WITH '(Fri) 09 Jan 2018 (32)' as inputString
WITH split(inputString, ' ') as parts
WITH parts[1] + ' ' + parts[2] + ' ' + parts[3] AS concatDate
RETURN apoc.date.parse(concatDate, 's',"dd MMM yyyy") as date;
Explanation:
- line 1: defines a date for testing purpose
- line 2: splits the given date into its pieces at each blank
- line 3: concatenates the day, month and year
- line 4: parse the built date of line 3 and convert it to a Neo4j date
Result
╒══════════╕
│"date" │
╞══════════╡
│1515456000│
└──────────┘
Alternative solution
WITH '(Fri) 09 Jan 2018 (32)' as inputString
WITH split(inputString, ' ') as parts
WITH reduce(s = "", x IN parts[1..4] | s + x) AS concatDate
RETURN apoc.date.parse(concatDate, 's',"ddMMMyyyy") as date;

ThirstForKnowledge
- 1,245
- 1
- 10
- 27
0
Assuming the date substring always starts at offset 6 in the input string, this will return the date offset from 01 Jan 1970
, which is adequate for comparing dates:
WITH '(Fri) 09 Jan 2018 (32)' as s
RETURN apoc.date.parse(SUBSTRING(s, 6, 11), 'd', "dd MMM yyyy") as date;

cybersam
- 63,203
- 6
- 53
- 76