3

I have two dates ,I want to get days between those two dates using SPARQL

I have refered SPARQL Calculating the difference between two date

but using above link I got only year ,but I want actual days between two date Please give me suggestion on same

thanks in advance.

  • So if those days are January 1, 2001 and January 3, 2002, you need 366 results? – Stanislav Kralin Apr 09 '18 at 12:09
  • 1
    Anyways, you can get year, month, day, via SPARQL. You can use VALUES to bind each month to the number of days. You can use multiplication + sum. The only difficulty would be with leap years. In the best case, you're using a triple store that provides extended time functions. – UninformedUser Apr 09 '18 at 14:46

1 Answers1

1

If you subtract dates, your answer is given in seconds. So you need divide the result by a number to specify the result in days: (3600 (number of seconds in an hour) times 24 (number of hours in a day). (If you would also multiply by 365, you would get the answer in years.)

So based on the reference you gave:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?age where { 
  bind( "1732-02-28"^^<http://www.w3.org/2001/XMLSchema#date> as ?death )
  bind( "1732-02-22"^^<http://www.w3.org/2001/XMLSchema#date> as ?birth )
  bind( (?death-?birth)/(3600*24) as ?age )
}

Resulting in the age in days:

"6"^^<http://www.w3.org/2001/XMLSchema#integer>
Richard
  • 1,224
  • 3
  • 16
  • 32