I have a strange behaviour in my CGridView when I want to sort dates - it doesn’t sort date-wise, but numerical-wise, meaning:
Instead of e.g.
2010/08/01
2010/08/03
2010/09/01
which would be the correct order, I get
2010/08/01
2010/09/01
2010/08/03
So it doesn’t go by day/month/year, but sorts in a numerical manor.
Could this be a bug or is there any feature I forgot to set?
In the GridView, I have set the type to date and have used strtotime to define a timestamp, so the type conversion of the CFormatter works correctly. In addition, there’s a fine working CSort in my model.
Any ideas?
Cheers,
Frank
P.S.: I am from Germany and have checked the issue independent of the date format, it won’t work with german (22.09.2010) / english (09/22/2010) / european (2010/09/22) date format
Ok guys, I’m a bit smarter regarding this issue - it is NOT related to Yii, but the problem still exists.
I have the issue in conjunction with a sqlite database. Using a Firefox plugin (SQLiteManager), I tried to sort and have received the same result, though the column explicitely is a date column, but is not sorted as such.
I will check this issue further and will inform you about my results.
OK, case closed for me, my mistake. Better RTFM (read the fine manual) as usual before asking questions
In my case, I quite forgot that, using sqlite, I am using a “typeless DB” which according to the mentioned SQLManager supported datetime, but in the end didn’t as I expected it. So long story short: SQLite stores all data as strings and sorts them accordingly.
Therefore: If you are using a sqlite database and try to store dates which you want to sort, you should be aware that storing them as e.g. INTEGER type (in my case) solves the trick of a correct sorting. You can use the INTEGER type to store a UNIX-type timestamp and convert it back for your specific usage.