query-553ba71386975ce2b7d546c00162d24f

rq turtle/ttl

You've Lived Longer Than...Hello all, I'm in need of some help writing a query. I need to produce data for notable people that a user has lived longer than. User inputs birthday > calculate "days lived" > Query people that have shorter lifespans > return results I'm having trouble converting lifespan to "days lived" to compare with against a user's input. Any help would be greatly appreciated :) You can subtract dateTime values to get the difference in days. An example: List dead physicists who lived longer than a living person who was born 1918-01-01:

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?personLabel ?person_age ?dateOfBirth ?dateOfDeath
{
  {
    SELECT ?person ?person_age ?dateOfBirth ?dateOfDeath
    {
      BIND(NOW() - "1918-01-01"^^xsd:date as ?age).
      ?person wdt:P31 wd:Q5.

      ?person p:P569/psv:P569 [
        wikibase:timeValue ?dateOfBirth;
        wikibase:timePrecision ?dob_precision
      ].
      FILTER(?dob_precision = "11"^^xsd:integer) # Precision is day

      ?person p:P570/psv:P570 [
        wikibase:timeValue ?dateOfDeath;
        wikibase:timePrecision ?dod_precision
      ].
      FILTER(?dod_precision = "11"^^xsd:integer) # Precision is day

      ?person wdt:P106/wdt:P279* wd:Q169470. # occupation is physicist
      BIND(?dateOfDeath - ?dateOfBirth as ?person_age).
      FILTER (?person_age > ?age)
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?age") v6("?dateOfBirth"):::projected v7("?dateOfDeath"):::projected v4("?dob_precision") v3("?dod_precision") v5("?person"):::projected v8("?person_age"):::projected a2((" ")) a1((" ")) a4((" ")) a3((" ")) a5((" ")) c12(["wd:Q169470"]):::iri c14(["bd:serviceParam"]):::iri c3(["wd:Q5"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?person_age > ?age"]] f0 --> v8 f0 --> v5 f1[["?dod_precision = '11^^xsd:integer'"]] f1 --> v3 f2[["?dob_precision = '11^^xsd:integer'"]] f2 --> v4 bind3[/"NOW() - '1918-01-01^^xsd:date'"/] bind3 --as--o v5 v5 --"p:direct/P31"--> c3 a1 --"wikibase:timeValue"--> v6 a1 --"wikibase:timePrecision"--> v4 v5 --"p:P569"--> a2 a2 --"p:statement/value/P569"--> a1 a3 --"wikibase:timeValue"--> v7 a3 --"wikibase:timePrecision"--> v3 v5 --"p:P570"--> a4 a4 --"p:statement/value/P570"--> a3 v5 --"p:direct/P106"--> a5 a5 --"p:direct/P279"--> c12 bind4[/"?dateOfDeath - ?dateOfBirth"/] v7 --o bind4 v6 --o bind4 bind4 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end