Search code examples
sparqlrdf

SPARQL How to get year as integer from xsd:date


I have a SPARQL query which choose people who has year of birth 1990. How could I get only year from xsd:date format? I can see how to get year from xsd:dateTime using year() but it doesn't work on xsd:date.

PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?birthYear
WHERE
{dbr:Ilse_DeLange dbo:birthDate ?birth
 #how to get year only as a integer?}

Solution

  • According to the specs, year() works on xsd:dateTime literals only.

    Depending on the triple store, you might try to convert to xsd:dateTime first:

    PREFIX dbr: <http://dbpedia.org/resource/>
    PREFIX dbo: <http://dbpedia.org/ontology/>
    SELECT DISTINCT (year(xsd:dateTime(?birthDate)) as ?birthYear) WHERE {
      dbr:Ilse_DeLange dbo:birthDate ?birthDate
    }