From: Suraj Kurapati Date: 2008-08-26T00:57:53+09:00 Subject: Re: setting date format to validate date in ruby Thomas B. wrote: > Jay Pangmi wrote: >> Thomas B. wrote: >>> You can have a look at this post: >>> http://al2o3-cr.blogspot.com/2008/08/downloading-file.html . There's >>> date validation in it, in the very general form, working with any >>> separator and any number of digits. It uses scanning for digit groups. >> >> Now what is bothering me is the logic to sort out the dates in the >> array. I tried the simplest way "Array.sort" but it only sorted the >> array according to the first value it sees not the whole date. How can I >> sort it out. Thanks > > Use the same approach as is used in the post I gave you link to: > - create Date objects for each date (once you parse it and see that it > is correct), and put the dates in an array, > - sort the array of dates, they will get sorted OK, > - convert dates back to strings if you need to, using Date#strftime. This can all be done *temporarily* if you use Array#sort_by: string_dates = [ ... ] result = string_dates.sort_by {|s| Date.parse s } Assuming that Date.parse is how you convert your string dates into Date objects. -- Posted via http://www.ruby-forum.com/.