Some SPARQL engines can directly support date arithmetic. For example, as mentioned in this question and answer.semanticweb.com answer , Jena supports date arithmetic, and you can subtract one date from another and get xsd: Duration. Other implementations may support the dating function. For example, this Virtuoso example includes the use of bif: datiff. However, these are extensions and are not guaranteed to be present in any particular SPARQL implementation.
For a more portable, albeit less efficient, solution, you can use year to extract parts of the year from date and time. This allows you, for example,
select ?age where { bind( "1799-12-14"^^<http://www.w3.org/2001/XMLSchema
and get the results
------- | age | ======= | 67 | -------
This can be disabled by one, depending on the months and days of two dates, but you can work around this in a similar way using month and day . This thread describes some of these implementations.
source share