How to compare 2 dates in sparql?

by giovanny.lueilwitz , in category: Third Party Scripts , 18 days ago

How to compare 2 dates in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 17 days ago

@giovanny.lueilwitz 

In SPARQL, you can compare two dates using the FILTER clause along with the xsd:dateTime or xsd:date functions to convert the date strings into date objects for comparison.


Here is an example query that compares two dates using the FILTER clause:

1
2
3
4
5
6
7
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?date
WHERE {
  ?s <http://example.org/dateProperty> ?date .
  FILTER (xsd:dateTime(?date) > "2022-01-01T00:00:00"^^xsd:dateTime)
}


In this query, we are selecting all dates that are greater than "2022-01-01T00:00:00". You can modify the comparison as needed to compare the dates in your dataset.