Search code examples
timestampsparqlrdfnosql

Getting current time in seconds/milliseconds with SPARQL?


Is there a way to get the current time in SPARQL as a duration in seconds or milliseconds from some epoch? The standard includes now(), which returns an xsd:dateTime, and a variety of functions for extracting parts of xsd:dateTimes, but nothing for converting the whole dateTime to seconds. Am I missing something?


Solution

  • Unfortunately, SPARQL 1.1 isn't required to support date arithmetic, although some implementations may. For instance, on the DBpedia endpoint, you can execute a query like this:

    select (NOW() - ?epoch as ?time ) where {
      values ?epoch { "1970-01-01T00:00:00"^^xsd:dateTime }
    }
    

    SPARQL results

    More details about the fact that SPARQL 1.1 isn't required to support this, along with some more portable workarounds (e.g., extracting components of dates and doing arithmetic with those) can be found in the answers to some related questions: