Is it possible to get the day of the week from a dateTime literal using SPARQL? I'm trying to infer whether a certain dateTime literal (retrieved from the 'now()' function) is on a certain day of the week. I'm aware of the year, month, day, hours, minutes, seconds and timezone functions, but not of a similar function returning the day of the week. If there's no such function, is there another way to infer the day of the week?
Okay, SPARQL 1.1... (Note SPARQL 1.1 has floor. You can calculate a % b (modulo) using a - (floor(a/b) * b).)
(EDIT: formula now (i) adjusts for January, February, (ii) ensures positive result, (iii) doesn't assume a four digit year.)
If you wanted to return names of the days, one quick trick would be to add triples of the following form to the store (assuming you have write access):
and then add:
to your query to retrieve the day name.
If you don't have write access, you could encode the day names into the query:
Not a sure if there is a function that will do it for you that is available in SPARQL. I'll let others more familiar with the spec help you with that, but if there isn't I think it would be a great exercise to see if you could roll your own using basic math functions (if enough of those are available). The formula for doing that can be found here
answered 24 Mar '12, 17:58