Parse date fields from mysql database

B

Bart Braem

I would like to be able to parse date fields from a MySQL database in order
to get the day, year, hour etc. separately. Which library could do that for
me? I can't think that I would have to parse those dates myself, right?

Bart
 
G

Gabriele Marrone

Il giorno 08/nov/06, alle ore 16:25, Bart Braem ha scritto:
I would like to be able to parse date fields from a MySQL database
in order
to get the day, year, hour etc. separately. Which library could do
that for
me? I can't think that I would have to parse those dates myself,
right?

Just use Date#day, Date#year, Date#hour and so on.
 
K

khaines

I would like to be able to parse date fields from a MySQL database in order
to get the day, year, hour etc. separately. Which library could do that for
me? I can't think that I would have to parse those dates myself, right?

require 'time'

parsed_time = Time.parse(mysql_datetime)


If the mysql field has a value that is outside the range for Ruby's Time
class, you can use DateTime:

require 'date'

parsed_time = DateTime.parse(mysql_datetime)



Kirk Haines
 

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
474,218
Messages
2,571,124
Members
47,727
Latest member
smavolo

Latest Threads

Top