On Sep 11, 2013, at 10:33 PM, Ketan Padegaonkar wrote:

> Hi,
> 
> I noticed that datetimes and timestamps are handled inconsistently between 
> databases. Mysql treats them as datetime[1]. Postgres treats them as 
> timestamp[2]. Sqlite treats them as datetime[3].
> 
> I read through the documentation around specifics of datetime and timestamps 
> in various databases and was wondering if there's a database specific nuance 
> that I do not understand or something else I'm missing. Could someone throw 
> some light at this?
> 

The best type to use to store DateTime objects is database-dependent:

- in Mysql, there are both TIMESTAMP and DATETIME column types, but TIMESTAMP 
is limited to the 32-bit UNIX epoch (1970-01-01 to 2038-01-19) while DATETIME 
accepts values between 1000-01-01 and 9999-12-31.

- in Postgres, there is only TIMESTAMP, which accepts values between 
-4713-01-01 and 294276-01-01 (or so...)

- SQLite doesn't exactly support a native DATETIME type, but it stores the 
values as strings. DATETIME is preferred (best I can tell) over TIMESTAMP 
because the SQLite gem parses TIMESTAMP columns into Time objects while 
DATETIMEs become DateTime objects.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to