Hi, 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? Regards, Jacco asked 24 Mar '12, 16:04 Jacco Signified ♦ 
Okay, SPARQL 1.1... (Note SPARQL 1.1 has floor. You can calculate a % b (modulo) using a  (floor(a/b) * b).) Using the Gaussian function in @harschware's link, this should give an ID for the current day of the week: (EDIT: formula now (i) adjusts for January, February, (ii) ensures positive result, (iii) doesn't assume a four digit year.)
You can test this here, with todays "day" here. 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:
Which gives the answer here. (Thanks to @database_animal for pointing me to the if–then–else ladder pattern.) answered 24 Mar '12, 22:09 Signified ♦ Nice, thanks for this! Really helpful. I didn't know there was a floor function in SPARQL 1.1. But your query doesn't substract the year with 1 if the month is january or february
(25 Mar '12, 07:30)
Jacco
@Jacco, good point: I missed that, but it's now fixed in the formula. With conditional branching it would be easier ( I also added something to make sure the result is positive, and now calculate the century/year using
(25 Mar '12, 10:15)
Signified ♦
UDPATE: Used conditions to clean up the formula a bit.
(25 Mar '12, 13:13)
Signified ♦

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 harschware ♦ Thanks, I'll look into that formula. Edit: Nice formula, will be useful to remember! Sadly SPARQL doesn't support modulus or floor calculations.
(24 Mar '12, 19:20)
Jacco
You were right about being a great exercise. My SPARQL foo has increased by three bar, particularly regarding some of the new functions and casting (which I think is poorly explained in the doc if @lee sees this; would be great to have an example since it's not clear that the cast function name is the datatype URI; I thought it was
(24 Mar '12, 22:53)
Signified ♦
I think I mighta gotten stuck with the modulus operator being missing so thanks for proving it could be done. And, since we're hoping @lee is listening... modulus operator, case function and of course, dayOfWeek function would also be great. :)
(26 Mar '12, 00:33)
harschware ♦
