This project is archived and is in readonly mode.
Date column bug
Reported by Jan Bernacki | March 15th, 2011 @ 09:23 AM
Hello.
create_table :downloads do |t|
t.date :downloaded_at
t.integer :count, :default => 0
end
Download.create(:downloaded_at => Time.now)
d = Download.first # => #<Download id: 1, downloaded_at: "2011-03-15", count: 0>
Download.where(:downloaded_at => d.downloaded_at) # => []
Database Mysql, SQLite, rails 3.0.5
if I use Download.create(:downloaded_at => Date.current), I find it after.
Maybe it's not a Bug, but intuitively, it seems that Time.now is correct.
Comments and changes to this ticket
-
Josh Kalderimis March 15th, 2011 @ 12:53 PM
- State changed from new to invalid
- Importance changed from to Low
Hi Releu,
The difference between
Time.now
andDate.current
is thatTime.now
has a higher precision.When you create a Download using
Time.now
it is cast to aDate
, thus losing its precision. But when you query for a Download usingTime.now
that precision is not cast but instead just passed to your DB. You can check this for yourself by looking at the logs.I will close this issue as it is not a bug.
Thanks
Josh
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>