Filter by date in SPARQL

I am using the Jena SPARQL engine and trying to write a query to filter on a date range, since I need to find the value of the property after a fixed date.

The my date property has the following format:

Fri May 23 10:20:13 IST 2014 

How to write a SPARQL query to get other properties with dates greater than this?

+6
source share
1 answer

With your data in this format, you cannot filter it in a range without adding the added custom XML Schema Specification Part 2: Datatypes .

Your specific example date will look like this:

 2014-05-23T10:20:13+05:30 

And you need to make sure that you declare it a typed literal of the xsd:dateTime type when you use it in data and queries. For example, in Turtle- readable RDF syntax:

 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix : <http://example.org> . :subject :date "2014-05-23T10:20:13+05:30"^^xsd:dateTime . 

Then you can write a SPARQL query that filters the date range, for example:

 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX : <http://example.org> SELECT * WHERE { ?s :date ?date . FILTER (?date > "2014-05-23T10:20:13+05:30"^^xsd:dateTime) } 

This finds all entries where ?date after the specified date

+13
source

Source: https://habr.com/ru/post/970361/


All Articles