I have to compare the date in rails to get the values after that date I have send the date as "2013-03-04T06:26:25Z"
but actually the record in the db contains date as follows 2013-03-04 06:26:25.817149
so when i check with the date it also returns that record but i want records after that date. how can i remove the milliseconds from the db? please help me.
I had a similar problem
Update your time object like this before sending it to the database :
time.change(:usec => 0)
Since ruby 1.9 you can use round
t = Time.now.round
t.usec # => 0
I was also having this problem, however when I was applying the change as indicated in @Intrepidd's answer, it wasn't affecting the microseconds of my time object.
Please note that (at least currently) the :usec
key only works with the Time#change
method, and not with the DateTime#change
method.
The DateTime#change
method ignores the keys that it doesn't accept, so you wouldn't be able to tell that your attempted change of the microseconds didn't work unless you inspected the object further (such as with DateTime#rfc3339(9)
).
So before you attempt this change, make sure that you are working with a Time
object, not a DateTime
object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With