How to compare 2 dates in sparql?

by giovanny.lueilwitz , in category: Third Party Scripts , 5 months ago

How to compare 2 dates in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 5 months 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.

Related Threads:

How to compare date values (xsd:date) with years in sparql?
How to compare two dates in moment.js?
How to compare the seconds between two dates to an integer in oracle?
How to compare dates using eloquent in laravel?
How to exclude weekend and compare current dates in mysql?
How to increment dates in sparql?