Search code examples
rdfsparqljenasemantic-web

year() function in SPARQL


I want to make a query in SPARQL that returns items of the year 2007. I tried this :

    String requete7String = 
            "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
          + "PREFIX dc: <http://purl.org/dc/elements/1.1/> "
          + "PREFIX rss: <http://purl.org/rss/1.0/> "
          + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
          + "SELECT ?item "
          + "FROM <http://www.w3.org/2001/sw/SW-FAQ-feed.rdf> "
          + "WHERE { "
          + "  ?item rdf:type rss:item . "
          + "  ?item dc:date ?dateString ."
          + "  bind(strdt(?dateString, xsd:dateTime) as ?date) "
          + "  FILTER (year(?date) = 2007) "
          + "}";

But it returns nothing. The line FILTER (year(?date) = 2007) doesn't work. However, I saw in SPARQL documentaiton that the function year() takes a dateTime and returns a integer, so can you tell me why it might not work?


Solution

  • 2007-04-12T00:00+00:00"^^xsd:dateTime isn't a legal xsd:dateTime (the time part should be 00:00:00, not 00:00. Therefore it is not a legal value and year(illegal) is error, and the filter is false.