Reputation: 41949
probably a bit of a noob question...I got partway to solving it on my own but...
I'm making a basis application that has a database of legal decisions, which will be represented in a table that would preferably have sortable columns whereever that's possible. For example, I wish to be able to sort them by date.
I'll be using class methods for this
def self.judgementdate
order("judgementdate DESC")
end
Questions: Should I create the column as a string or an integer? How should I enter the date into the database to make it most easily sortable. for example, should I enter January 27, 2012 as
27/01/2012
or
"January 27, 2012"
or something else?
Upvotes: 0
Views: 53
Reputation: 434685
You should use a date
column to store dates, not string
nor integer
, date
. Then the database will sort them just fine and even know how to manipulate them as dates; if you use some other type then you'll end up doing bizarre string mangling or a bunch of pointless (and probably incorrect in edge cases) arithmetic.
Upvotes: 1
Reputation: 41949
Silly me, after I posted the question, I realized I should just check the automatically generated created_at columns for the proper date format. so I'm entering date like this. Rails sorts it fine!
2012-07-26
Upvotes: 0