Reputation: 95
I am trying to sort my objects by date, descending. The dates are on the following format: dd-MM-yyyy. How can i sort this with substring?
Edit: I currently have
"order by substr(Date, 7, 4),substr(Date, 4, 2), substr(Date, 1, 2) DESC";
Which, according to documentation for substr, should do the trick.
The problem is that 1-12-2014 and 2-12-2015 appears between 10-1-2014 and 9-1-2014, like this:
10-1-2014
1-12-2014
2-12-2015
9-1-2014
Which should appear like this
2-12-2015
1-12-2014
10-1-2014
9-1-2014
Upvotes: 0
Views: 1300
Reputation: 95
It's solved now, I had to make sure all my dates was on this form: 01-01-2010 (instead of 1-1-2010) and use this line
"order by substr(Date, 7, 4) DESC,substr(Date, 4, 2) DESC, substr(Date, 1, 2) DESC";
Upvotes: 2