How can I format properties datatype as date

Dear all.
As you can see in the picture.


The command is so easy
match (c:Company)-[r:RELATED_EVENT]->(us:UpdateShare)

return c.name,c.code,us.date,us.note

order by us.date DESC

and i have orderd by us.date But you can see it not ordering in the right order because us.date now is string note date time.

How can I format it without losing data.

Thanks.

@nguyentuananh92

the date doesn't appear to be in a traditional US date format. Typically US dates are in the form of Month-Day-Year,

However for example

with "31/03/2010" as dateExample return date(split(dateExample,'/')[2] + split(dateExample,'/')[1] + split(dateExample,'/')[0]);

returns

2010-03-31

and this might be best for your example so as to get proper sorts.

maybe change your

match (c:Company)-[r:RELATED_EVENT]->(us:UpdateShare)
return c.name,c.code,us.date,us.note

order by us.date DESC

to

match (c:Company)-[r:RELATED_EVENT]->(us:UpdateShare)
return c.name,c.code,us.date,us.note

order by date (   split(us.date,'/')[2] +  split(us.date,'/')[1]  +  split( us.date,'/')[0]  )   DESC
Try this:
return c.name, c.code, apoc.date.format(apoc.date.parse(us.date, 's',"dd/MM/yyyy"), 's', "dd/MM/yyyy") as dte, us.note
order by dte DESC

It doesn't work sir.

It work so good sir. It return a right order.
Can I format this property to date format so that next time, no need to format again sir?

Please send me one row from your .csv file so that I can test it. Thanks

Try this:

with c.name, c.code, us.date, apoc.date.parse(us.date, 's',"dd/MM/yyyy") as scnds, us.note
with c.name, c.code, us.date, us.note, scnds order by scnds DESC
return c.name, c.code, us.date, us.note

I suggest you store the value as a Date type or a string in YYYY-MM-DD format. This way you will be able to sort chronologically. A Date value has additional capabilities that make it more useful than a string, but which to chose depends on your requirements and anticipated needs.

1 Like

Yes, I want to convert the old data to the format that you suggest me without losing data.

I have upload dump file to here

Hoping that, you keep an eye on it and help me.
Thanks

I requested access to the file.

You could run something like the following to remediate your data. I would replace the string 'date' value all together instead of storing both attributes.

match(us:UpdateShare)
set us.formattedDate = Date({
    day: toInteger(left(us.date, 2)), 
    month: toInteger(substring(us.date, 3, 2)), 
    year: toInteger(right(us.date, 4))
})

OR

match(us:UpdateShare)
set us.formattedDate = Date(right(us.date, 4) + "-" + substring(us.date, 3, 2) + "-" + left(us.date, 2))

You will want to test it on a small set of data. You can do this by using the LIMIT clause. Also, if the number of nodes is above 10,000, you may want to use a call subquery in transactions.

Sorry sir, I have changed so anybody can access it with the link

It is ok sir.
Do you have any suggestion about modelling.

During the timeline.
Each company can change:

  • their own share so I create UpdateShare Node.
  • Their address so I create UpdateAddress Node.
    -And Company A can change the number of share they have from other company (Company B) at each UpdateShare Node.
    For person it is also the same. They also can change their role at the company.

To be honest, maintaining version history in a graph model seems difficult to me. What other solutions have you thought about? This seems like an accounting problem. You could record each transaction in an event table and replay the events to reconcile a stock when needed. You could checkpoint the data periodically so you don’t have to replay from t=0.

1 Like

Hi, Thanks for sharing the db dump. I used your dump file and created the db in my Neo4j Desktop.
I have some ideas of about improving the design especially the Update nodes and timelines. If you want this to be private, you can email me at ameyasoft@gmail.com. Let me know. Thanks

Hi,
Thanks for sending this email. In a couple of days I will get in touch with you.
-Ameyasoft

Why don't you discuss here for more comment.
I also have emailed you.
Thanks.