I have a SQLITE DB with a string field which contains a date in the following format: “01.01.2012”.
What I want is to sort the by this string formatted date in a query.
I tried this without success:
SELECT * FROM fahrer, fahrzeuge, nutzungsarten, fahrtenbuch WHERE fahrtenbuch.nutzungsart_id = nutzungsarten._id AND fahrtenbuch.fahrzeuge_id = fahrzeuge._id AND fahrtenbuch.fahrer_id = fahrer._id ORDER BY strftime ('%d.%m.%Y', fahrtenbuch.startdatum)
What I am doing wrong?
The values in the
startdatumcolumn are not in a format that SQLite recognizes, so you cannot use it as a parameter tostrftime.(Even if it worked, the result would not be sorted correctly because that date format does not begin with the most significant field, the year.)
You could try to extract the date fields so that the sorting is equivalent with the
yyyy-mm-ddorder:But I would recommend to convert the values into a supported format in the first place.