Best MySQL date/time data type when using Ruby?

J

John N Joyner

In the years when I used PHP to develop web apps, I found either a MySQL
TIMESTAMP or an integer of the same value was most convenient for
storing date/time information and then converting back and forth using
PHP functions.

Now that I'm using Ruby, I'm wondering whether the MySQL DATETIME type
might be a better match with the Ruby Date class and its methods, based
on looking at the Date class documentation. I'd be interested to know
whether Rubyists who use MySQL mostly use the DATETIME data type or the
TIMESTAMP data type? (I'm not using ROR, though I have nothing against
it.)

Any input much appreciated.
 
J

John Joyce

In the years when I used PHP to develop web apps, I found either a
MySQL
TIMESTAMP or an integer of the same value was most convenient for
storing date/time information and then converting back and forth using
PHP functions.

Now that I'm using Ruby, I'm wondering whether the MySQL DATETIME type
might be a better match with the Ruby Date class and its methods,
based
on looking at the Date class documentation. I'd be interested to know
whether Rubyists who use MySQL mostly use the DATETIME data type or
the
TIMESTAMP data type? (I'm not using ROR, though I have nothing against
it.)

Any input much appreciated.

You don't need to use Rails to use its database ORM component
ActiveRecord. ActiveRecord doesn't do the timestamp mysql type really
the way you would expect (AFAIK). It instead chooses to simple store
a datetime and let you manage that date data in Ruby code instead.

If you choose to use Ruby DBI gem, it is more what you might be used
to with PHP or Perl more direct SQL stuff.

Either approach works pretty well in Ruby, since the Ruby classes
Time and Date have a lot of nice functionality built in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top