how do i convert a date format to “DD-MM-YYYY” or “DD/MM/YYYY”
i have tried
, to_char((a.endpoint_last_scanned),‘DD-MM-YYYY’)
i have tried
,SUBSTRING(tostring(a.endpoint_last_scanned),9,2)+‘/’+SUBSTRING(tostring(a.endpoint_last_scanned),5,2)+‘/’+SUBSTRING(tostring(a.endpoint_last_scanned),0,4)
We don’t yet have a “strftime”-style function in our cypher implementation, but you can still get the desired output using a combination of tostring+split+join.
The easiest option would be to just combine tostring+split, which would yield YYYY-MM-DD format.
However, if you’re looking for MM-DD-YYY, you can use the cypher below:
match (a:Asset)
// convert the date to string
with tostring(a.endpoint_last_scanned) as date_string
// separate the yyyy_mm_dd prefix from the timestamp
with head(split(date_string, "T")) as YYYY_MM_DD
// split into the date parts
with split(YYYY_MM_DD,"-") as date_parts
// join the result
return join([date_parts[1], date_parts[2], date_parts[0]],"/") as MM_DD_YYY
limit 1
This will output: 01/24/2025 (MM/DD/YYYY) format.
Your approach using substring would also work, but it looks like the indexes in your example are slightly off.
Here is a version using the SUBSTRING+offset approach:
match (a:Asset)
return SUBSTRING(tostring(a.endpoint_last_scanned),8,2)+'/'+SUBSTRING(tostring(a.endpoint_last_scanned),5,2)+'/'+SUBSTRING(tostring(a.endpoint_last_scanned),0,4)
limit 1
I changed the 9 to an 8 in the first substring function to avoid grabbing the T time separator.