Is it possible to extract month element from the date using SPARQL and group results by it. I am using W3 time ontology for defining dates in format "2009-12-31"^^xsd:date
.
So in case of "2009-12-31"^^xsd:date
I would like to extract 12
.
Is this even possible. If so, how can do that?
In SPARQL 1.1 there's a month() function (http://www.w3.org/TR/sparql11-query/#func-month) which extracts the month from ISO dates.
you can group by month using the GROUP BY keyword, as in:
SELECT ?mon SUM(?val)
WHERE {
?x :date ?date ;
:value ?val .
}
GROUP BY (month(?date) AS ?mon)
The only slight problem is that SPARQL systems aren't required to process xsd:date datatypes, just xsd:dateTime, but many will handle it correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With