Support for temporal types in Memgraph

Hi there,

I was looking at the documentation of Memgraph and noticed that there is no support for temporal types such as timestamp or periods. Do you have plans to include them in the future?

I need to write queries where I filter nodes or edges within some time period e.g. the last hour or last 24 hours.

Thanks.

1 Like

Hey @Jb21,

Really good question. We do have plans to expand data types to include timestamps, spatial information (lat, long), etc., but I don’t have a timeline when exactly.

In the meantime, there are two ways to do it:

  1. saving a date-time in timestamp format: epoch milliseconds - results in a number that can be compared and used with timestamp function that we support in Cypher: https://docs.memgraph.com/memgraph/reference-overview/other-features
  2. saving a date-time in string ISO 8601 format because it is sortable format and can be easily used for checking periods

The difference between these two approaches is:

  • saving as a timestamp in milliseconds gives you the ability to compare periods within Cypher itself, e.g. last 10 minutes would be:
    MATCH (n: USER) WHERE timestamp() - 10 * 60 * 1000 < n.created_at RETURN n;
  • saving as ISO 8601 is more human-readable and can be sorted but in order to get last 10 minutes, business logic needs to find that particular timestamp 10 minutes ago which would be, e.g.: 2020-02-13T14:00:00.000Z (if now is 2020-02-13T14:10:00.000Z). Cypher would look like this:
    MATCH (n: USER) WHERE ‘2020-02-13T14:00:00.000Z’ < n.created_at RETURN n;

I hope this helps.

Cheers,
Karim

1 Like

@Karim.T,

Thank you. That is really helpful!

1 Like