Ordering results by date types in the public SPARQL endpoint

Hello. In relation to a project I’m working on, I’m trying to get the oldest date that’s related to a resource in Wikipedia. I used the following query in DBpedia’s public SPARQL explorer to get the first 100 birth dates (although I’m interested in any object of type xsd:date):

select ?object ?date ?link
where {
 ?object dbo:birthDate ?date .
 ?object foaf:isPrimaryTopicOf ?link .
}
order by ?date
limit 100

However, dates seem to sorted alphabetically instead of numerically. Is this the expected behavior for Openlink Virtuoso? I tried sorting dates of a small dataset with Apache Jena and it works as expected.

I’m not sure I understand you. This is the query you posted. How is alphabetic date sorting different to numeric sorting? 0001-02-01 as the smallest date makes sense to me, per se. Although I too wonder how dates BC are portrayed

Exactly, BC dates exist in Wikipedia but they are considered larger than AD dates. Strictly speaking this is not alphabetical sorting because ‘-’ < ‘0’ (so they should still appear before AD) and BC dates themselves are correctly sorted between each other (’-106-09-29’ < ‘-100-12-07’) which also doesn’t correspond to the alphabetical order. So there seems to be some specific condition switching the order of BC and AD. Try the following query to see dates of both types.

select ?object ?date ?link
where {
 ?object dbo:birthDate ?date .
 ?object foaf:isPrimaryTopicOf ?link .
 FILTER (
  ?date = "-017-12-11"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-043-03-20"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-065-12-08"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-070-10-15"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-083-01-14"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-100-07-12"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-106-09-29"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-106-01-03"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-106-01-03"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-106-01-03"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-106-01-03"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "-1796-09-28"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0001-02-01"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0002-02-03"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0004-03-05"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0004-08-04"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0007-05-25"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0009-01-09"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0012-05-24"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0017-05-02"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0018-07-10"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0019-02-02"^^<http://www.w3.org/2001/XMLSchema#date> ||
  ?date = "0019-03-23"^^<http://www.w3.org/2001/XMLSchema#date>
 )
}
order by ?date