Sorting dates in a Listcontrol
-
Hi I have a problem with sorting dates in a Listcontrol. When I add some dates they are sorted by day but I want to sort them by day AND month AND year of course. How do I do that? (sorry for the probably stupid question) now I get e.g. 1. 13 May 2003 2. 14 February 2005 3. 15 August 2001 4. 16 May 2003 And I want 1. 15 August 2001 2. 13 May 2003 3. 16 May 2003 4. 14 February 2005 please help me!:confused:
-
Hi I have a problem with sorting dates in a Listcontrol. When I add some dates they are sorted by day but I want to sort them by day AND month AND year of course. How do I do that? (sorry for the probably stupid question) now I get e.g. 1. 13 May 2003 2. 14 February 2005 3. 15 August 2001 4. 16 May 2003 And I want 1. 15 August 2001 2. 13 May 2003 3. 16 May 2003 4. 14 February 2005 please help me!:confused:
The sorting that is being performed is a string sort - i.e. they are in alphanumeric order. What you need to do in the sorting function is convert the textual representation of the date to say, a CTime, then determine the order from that. The other option is to display the date in the format YYYY/MM/DD; when you do this the string sort operation correctly sorts the dates!