How to convert date format in SPARQL?

date, sparql

Solution

Assuming the date values in DBPedia you are selecting are valid `xsd:dateTime` strings (the string you have in your question is not valid), you can easily do this as follows:

   SELECT ?x (CONCAT(STR(MONTH(?date)), 
                     "/", 
                     STR(DAY(?date)), 
                     "/", 
                    STR(YEAR(?date))) as ?displayDate)
   WHERE {
              ?x :hasDate ?date.
   }
   ORDER BY ?date

Problem

I am new to SPARQL and searched the web for quite some time now. My endpoint is http://dbpedia.org/sparql and I am using http://yasgui.laurensrietveld.nl/ to execute the queries. I can retrieve the date which looks like 1994-04-11 00:00:00. Now for display purpose, I need to show the date as MM/DD/yyyy format i.e. 4/11/1994. Is there any function which will help me ? I dont want to use STR , CONCAT ,YEAR, MONTH, DAY functions since I want the query results to be sorted by earliest date. EDIT: My query has group by ?name order by ?date. I want to get the earliest date. e.g. for "abc", I have three dates, 10/13/2001; 10/15/2007 and 10/22/2007. I want to get the earliest date 10/13/2001.

Original source