rails/rails — Issue #3519: Unable to retrieve record using datetime/timestamp column.
Author: mattscilipoti
Created: 2011-11-04 14:35:05+00:00
State: open

I have a table called :emails.

``` ruby

class CreateEmails < ActiveRecord::Migration
def self.up
create_table :emails do |t|
t.datetime :sent_at
...
t.timestamps
end
end
end
```

The generated structure:

``` t-sql
CREATE TABLE emails (
id integer NOT NULL,
...
sent_at timestamp without time zone,
created_at timestamp without time zone,
updated_at timestamp without time zone
```

I am unable to retrieve a record from Email using ether of the datetime fields.

``` ruby
> Email.create!(:sent_at => Time.now)
=> #

> Email.where(:sent_at => "2011-11-04 14:21:57")
=> []
```

The same happens with created_at and updated_at.

I believe it is a question of precision.
It finds the email where :sent_at is between 14:21:57 and 14:21:58.

Shouldn't we be able to retrieve this record using our normally formatted datetime strings?