How to precisely compare dates in rails using SQL? -
i didn't notice until run rspecs , difference between model creations in order of milliseconds, because it's fast.
created_at of first model: 2014-10-29 23:26:54 utc
created_at of sec model: 2014-10-29 23:26:54 utc
so, in tests want sec model have created_at bigger first, example. fails because query ignores milliseconds. example: 2014-10-29 23:26:54 .027824 utc
query comparing dates:
model.where("created_at > #{another_model.created_at}") query output
select "models" created_at > '2014-10-29 23:26:54 utc' how exactly compare dates in rails? in advance
i go with:
model.where('id > ?', another_model.id) since added later db means has greater id. unless utilize random ids or uuids.
if need deal fractual seconds have @ mysql fractional seconds. can add together fractional seconds precision time columns when create table. seems mysql not back upwards milliseconds out of box.
sql ruby-on-rails ruby rspec
No comments:
Post a Comment