Hi all, I want to sort dates of form "Month year". I''ve list of all dates in my database like , "Jan 2006" "Apr 2006" "Feb 2006" "Dec 2005" .... All are in as string. Is there any logic/method to sort them and display. I am stucked with this problem. Please Help me out. Thanks, -- 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-/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 -~----------~----~----~----~------~----~------~--~---
aveo wrote:> Hi all, > I want to sort dates of form "Month year". > I''ve list of all dates in my database like , "Jan 2006" "Apr 2006" "Feb > 2006" "Dec 2005" ....I got the solution and working.. g=''Jan 2007'' g1=''Dec 2006'' g2=''Mar 2007'' gd= Date.strptime(g, ''%b %Y'') gd1= Date.strptime(g1, ''%b %Y'') gd2= Date.strptime(g2, ''%b %Y'') puts [ gd,gd1,gd2 ].sort puts gd.strftime(''%B %Y'') ===> 2006-12-01 2007-01-01 2007-03-01 January 2007 Thanks -- 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-/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 -~----------~----~----~----~------~----~------~--~---
I got the solution and working..> > g=''Jan 2007'' > g1=''Dec 2006'' > g2=''Mar 2007'' > gd= Date.strptime(g, ''%b %Y'') > gd1= Date.strptime(g1, ''%b %Y'') > gd2= Date.strptime(g2, ''%b %Y'') > > puts [ gd,gd1,gd2 ].sort > puts gd.strftime(''%B %Y'') > > ===> > 2006-12-01 > 2007-01-01 > 2007-03-01 > January 2007But how can use it for dynamic content like, <% @met.projects.each do |project| %> <br><%= project.duration_from %> ----------- Here I want to collect all duration_from from project table and get list of sorted duration_from---------------- <% end %> Please help me out, Thanks, -- 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-/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 -~----------~----~----~----~------~----~------~--~---