charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 16:09 UTC
convert unix time to mysql datetime
Hi, 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? Charlie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 16:12 UTC
Re: convert unix time to mysql datetime
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). Charlie On Jun 7, 9:09 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > 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? > > Charlie--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
some_time = Time.now some_time.to_s(:db) On Jun 7, 12:12 pm, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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). > Charlie > > On Jun 7, 9:09 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > 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? > > > Charlie--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
One other thing XML has it''s own standard for time. ./script/console>> some_time = Time.now=> 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 Jun 7, 12:55 pm, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> some_time = Time.now > some_time.to_s(:db) > > On Jun 7, 12:12 pm, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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). > > Charlie > > > On Jun 7, 9:09 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > > 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? > > > > Charlie--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 17:53 UTC
Re: convert unix time to mysql datetime
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 Time.at 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 time.at, like this: publish_date_unix = news_publish_dates[idx] newslistings_publish_date = Time.at(publish_date_unix) And I get this error: can''t convert String into time Charlie On Jun 7, 10:07 am, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> One other thing XML has it''s own standard for time. > > ./script/console>> some_time = Time.now > > => 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 Jun 7, 12:55 pm, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > some_time = Time.now > > some_time.to_s(:db) > > > On Jun 7, 12:12 pm, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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). > > > Charlie > > > > On Jun 7, 9:09 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > > 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? > > > > > Charlie--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 17:55 UTC
Re: convert unix time to mysql datetime
One more thing -- when I say, at the console puts Time.at(1181083337) it works -- I get Tue Jun 05 15:42:17 -0700 2007 Charlie On Jun 7, 10:53 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 Time.at 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 time.at, like this: > > publish_date_unix = news_publish_dates[idx] > newslistings_publish_date = Time.at(publish_date_unix) > > And I get this error: > > can''t convert String into time > > Charlie > > On Jun 7, 10:07 am, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > One other thing XML has it''s own standard for time. > > > ./script/console>> some_time = Time.now > > > => 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 Jun 7, 12:55 pm, Robert Walker <rwalker...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > some_time = Time.now > > > some_time.to_s(:db) > > > > On Jun 7, 12:12 pm, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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). > > > > Charlie > > > > > On Jun 7, 9:09 am, "charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" > > > > > <charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > > > > 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? > > > > > > Charlie--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 7, 2007, at 1:55 PM, charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:>> Time.at(publish_date_unix)perhaps: Time.at(publish_date_unix.to_i) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
charlie.caroff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-07 18:13 UTC
Re: convert unix time to mysql datetime
Got it, thank you. On Jun 7, 11:01 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jun 7, 2007, at 1:55 PM, charlie.car...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > >> Time.at(publish_date_unix) > > perhaps: > > Time.at(publish_date_unix.to_i) > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---