Forum: Ruby on Rails convert unix time to mysql datetime

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
on 2007-06-07 20:09
(Received via mailing list)

I have a unix timestamp in an xml feed that I want to convert to a
mysql datetime before I put it into my database.  Any hints?

on 2007-06-07 20:12
(Received via mailing list)
Let me ask this another way.  Is it possible to store it in mysql as a
unix timestamp, then format it the way I want it, if I ever want to
display it?  When I try to put it in my mysql database as a unix
timestamp, it's rejected (the column format is datetime).

On Jun 7, 9:09 am, "removed_email_address@domain.invalid"
Robert W. (Guest)
on 2007-06-07 20:57
(Received via mailing list)
some_time =

On Jun 7, 12:12 pm, "removed_email_address@domain.invalid"
Robert W. (Guest)
on 2007-06-07 21:08
(Received via mailing list)
One other thing XML has it's own standard for time.

>> some_time =
=> Thu Jun 07 12:58:50 -0400 2007
>> some_time.to_s(:db)
=> "2007-06-07 12:58:50"
>> some_time.xmlschema
=> "2007-06-07T13:02:53-04:00"

Also take a look at Time::parse class method for converting string
representations of time into ruby Time objects.
on 2007-06-07 21:54
(Received via mailing list)
I can't see how to use Time::parse to turn a unix epoch timestamp
(like 1181083337) into a date time format I can put into the database.

I see, though, from the Class:Time document page, that can do
this.  But I get an error when I try:

While I'm importing xml in my controller, and before I put the time
into the database, I try to convert it from unix epoch time into a
datetime with, like this:

      publish_date_unix = news_publish_dates[idx]
    newslistings_publish_date =

And I get this error:

can't convert String into time

on 2007-06-07 21:56
(Received via mailing list)
One more thing -- when I say, at the console


it works -- I get

Tue Jun 05 15:42:17 -0700 2007


On Jun 7, 10:53 am, "removed_email_address@domain.invalid"
Rob B. (Guest)
on 2007-06-07 22:02
(Received via mailing list)
On Jun 7, 2007, at 1:55 PM, removed_email_address@domain.invalid wrote:




Rob B.
on 2007-06-07 22:14
(Received via mailing list)
Got it, thank you.

On Jun 7, 11:01 am, Rob B. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.