Why is Rails displaying date like: Sat Jan 01 13:31:00 UTC 2000 When the date is clearly correct in the database: reverseblade_development=> select * from blogs; id | postdate | posttitle | post | created_at | updated_at ----+----------+------------+-------+----------------------------+---------------------------- 4 | 13:31:00 | Test again | again | 2009-12-22 18:32:06.800273 | 2009-12-22 18:32:06.800273 Here is the code that displays the date: <% @blogs.each do |blog| %> <%=h blog.postdate%><br> <%=h blog.posttitle %><br> <%=h blog.post %><br> <%= link_to ''Show'', blog %> <%= link_to ''Edit'', edit_blog_path(blog) %> <%= link_to ''Destroy'', blog, :confirm => ''Are you sure?'', :method => :delete %> <% end %> Is there some sort of conversion that I am missing someplace? - Rilindo -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rilindo Foster wrote:> Why is Rails displaying date like: > > Sat Jan 01 13:31:00 UTC 2000 > > When the date is clearly correct in the database: > > reverseblade_development=> select * from blogs; > id | postdate | posttitle | post | created_at | > updated_at > ----+----------+------------+-------+----------------------------+---------------------------- > 4 | 13:31:00 | Test again | again | 2009-12-22 18:32:06.800273 | > 2009-12-22 18:32:06.800273Your ''postdate'' is stored as ... Just a time! So Rails defaults to Jan. 01, 2000. You may want to do a migration and change your column to a datetime... ? As usual, beware of modifying pre-existing data. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 22, 2009, at 11:54 AM, Rilindo Foster wrote:> Why is Rails displaying date like: > > Sat Jan 01 13:31:00 UTC 2000 > > When the date is clearly correct in the database: > > reverseblade_development=> select * from blogs; > id | postdate | posttitle | post | created_at > | updated_at > ----+----------+------------+-------+---------------------------- > +---------------------------- > 4 | 13:31:00 | Test again | again | 2009-12-22 18:32:06.800273 | > 2009-12-22 18:32:06.800273postdate doesn''t look like a date to me. It looks like a time...> > Here is the code that displays the date: > > <% @blogs.each do |blog| %> > <%=h blog.postdate%><br> > <%=h blog.posttitle %><br> > <%=h blog.post %><br> > <%= link_to ''Show'', blog %> > <%= link_to ''Edit'', edit_blog_path(blog) %> > <%= link_to ''Destroy'', blog, :confirm => ''Are you sure?'', :method > => :delete %> > <% end %> > > Is there some sort of conversion that I am missing someplace? > > - Rilindo > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > . > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting Rilindo Foster <rilindo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Why is Rails displaying date like: > > Sat Jan 01 13:31:00 UTC 2000 > > When the date is clearly correct in the database: > > reverseblade_development=> select * from blogs; > id | postdate | posttitle | post | created_at | updated_at > ----+----------+------------+-------+----------------------------+---------------------------- > 4 | 13:31:00 | Test again | again | 2009-12-22 18:32:06.800273 | 2009-12-22 18:32:06.800273 > > > Here is the code that displays the date: > > <% @blogs.each do |blog| %> > <%=h blog.postdate%><br> > <%=h blog.posttitle %><br> > <%=h blog.post %><br> > <%= link_to ''Show'', blog %> > <%= link_to ''Edit'', edit_blog_path(blog) %> > <%= link_to ''Destroy'', blog, :confirm => ''Are you sure?'', :method => :delete %> > <% end %> >Note: postdate column is a TIME (13:31:00), i.e. time of day. Use a datetime type in the database. HTH, Jeffrey -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Oh my goodness you''re right. Unfortunately, I couldn''t seem to change the column type gracefully with postgres: (in /Users/rilindo/src/rrproj/reverseblade) == ModifyPostdateColumn: migrating ==========================================-- change_column(:blogs, :postdate, :datetime) rake aborted! An error has occurred, this and all later migrations canceled: PGError: ERROR: column "postdate" cannot be cast to type "pg_catalog.timestamp" : ALTER TABLE "blogs" ALTER COLUMN "postdate" TYPE timestamp (See full trace by running task with --trace) tristan:reverseblade rilindo$ rake db:migrate (in /Users/rilindo/src/rrproj/reverseblade) == ModifyPostdateColumn: migrating ==========================================-- change_column(:blogs, :postdate, :datetime) rake aborted! An error has occurred, this and all later migrations canceled: PGError: ERROR: column "postdate" cannot be cast to type "pg_catalog.timestamp" : ALTER TABLE "blogs" ALTER COLUMN "postdate" TYPE timestamp I ended up having to rename the column and added a new one: class ModifyPostdateColumn < ActiveRecord::Migration def self.up rename_column :blogs, :postdate, :old_postdate add_column :blogs, :postdate, :datetime end def self.down remove_column :blogs, :postdate rename_column :blogs, :old_postdate, :postdate end end Now It is displaying the right date. Thanks! On Dec 22, 2009, at 3:10 PM, Jeffrey L. Taylor wrote:> Quoting Rilindo Foster <rilindo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> Why is Rails displaying date like: >> >> Sat Jan 01 13:31:00 UTC 2000 >> >> When the date is clearly correct in the database: >> >> reverseblade_development=> select * from blogs; >> id | postdate | posttitle | post | created_at | updated_at >> ----+----------+------------+-------+----------------------------+---------------------------- >> 4 | 13:31:00 | Test again | again | 2009-12-22 18:32:06.800273 | 2009-12-22 18:32:06.800273 >> >> >> Here is the code that displays the date: >> >> <% @blogs.each do |blog| %> >> <%=h blog.postdate%><br> >> <%=h blog.posttitle %><br> >> <%=h blog.post %><br> >> <%= link_to ''Show'', blog %> >> <%= link_to ''Edit'', edit_blog_path(blog) %> >> <%= link_to ''Destroy'', blog, :confirm => ''Are you sure?'', :method => :delete %> >> <% end %> >> > > Note: postdate column is a TIME (13:31:00), i.e. time of day. Use a datetime > type in the database. > > HTH, > Jeffrey > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.