Sort distance_of_time_in_words hash

I have a hash with the key generated by distance_of_time_in_words. I want to be able to sort that hash chronologically instead of alphabetically. How would I do that?

i.e., the keys in my hash are "6 days", "25 days", "5 months". I want to sort it in that order but what happens is the .sort method sorts it alphabetically and puts it "25 days", "5 months", "6 days".
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew DoadesIT TechnicianCommented:
Can you not use the DESC ASC after the .sort?
victornegriAuthor Commented:
DESC and ASC don't change the way the sort function works. I need to change the sort so that it sorts chronologically and not alphabetically.

Is there a way to change the results of distance_of_time_in_words back to a date value first, sort it, and then change it back to distance_of_time_in_words?
You should sort your data by the original date value and after that you can translate the date to string with distance_of_time_in_words.

By the way, you lose some information after using distance_of_time_in_words method, so sorting by the string value can give you different result from sorting by the "real" date format.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

victornegriAuthor Commented:
But then how do I group by the distance_of_time_in_words value after sorting by the original date? Do I need to write a new method?
just check the other thread, maybe there is the solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.