4

I get the following error.

Virtuoso 22007 Error DT006: Cannot convert -0359 to datetime : Incorrect month field length

SPARQL query:
define sql:big-data-const 0 
#output-format:text/html
define sql:signal-void-variables 1 select ?item  bif:year(xsd:dateTime( str(?dob))) as ?m{
?item <h://f.cm/ns/common/topic/notable_types> <h://f.cm/ns/people/person> .
?item <h://f.cm/ns/people/person/date_of_birth> ?dob 
} limit 675

If I change the limit to 674, it works.

What I suspected was that some datetime field is wrong somewhere and printed ?dob, which revealed that one of the values is -0359.

Solution is to validate the value before applying bif function.

But, how can we validate datetime in SPARQL?

TallTed
  • 9,069
  • 2
  • 22
  • 37
nizam.sp
  • 4,002
  • 5
  • 39
  • 63

1 Answers1

5

Well, I found this question via Google because I had the same problem. Looking elsewhere for help, I found the following solution:

SELECT * {

  ?s ?p ?o

  FILTER ( datatype(?o) = xsd:datetime )
  FILTER ( coalesce(xsd:datetime(str(?o)), '!') != '!')

}

This worked for me.

Note that I found the answer to this at SemanticWeb.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Just a student
  • 10,560
  • 2
  • 41
  • 69
  • No luck with same approach here. Also no luck with: FILTER (regex(str(?o), '^[0-9][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]')) FILTER (xsd:datetime(?o) > '" + minBirthDate + "'^^xsd:datetime). What is coalesce(...) here? – TextGeek Apr 30 '14 at 16:23
  • Coalesce in the above query does what the name suggests: it concatenates the result of the conversion of ?o to a datetime with an exclamation mark. If the result of that is just an exclamation mark, then that means that the datetime is empty and hence, ?o was not a valid datetime. Since we filter on results that do NOT coalesce to just '!', we filter on values that are indeed a valid datetime. Does that make it more clear to you? – Just a student May 03 '14 at 12:56
  • @TextGeek ... a bit late, but does your minBirthDate really have xsd:datetime or just xsd:date (like mine) :) `FILTER ( datatype(?sdate) = xsd:date ) FILTER ( coalesce(xsd:date(str(?sdate)), '!') = '!')` – Richard Oct 08 '17 at 11:18
  • 1
    @Richard Sorry, I don't recall after this long; I probably just copied and pasted it from my code, so it would be as shown... :( – TextGeek Oct 09 '17 at 13:09