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:
- 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
- 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.