Alex Rivera | Logout

Ruby code to get the date of next Monday (or any day of the week)

Asked 2011-10-28T14:11:55.320
58

Given an input of, for example,

day = 'Monday'

how can I calculate the date of the next day?

def date_of_next(day)
  ...
end
Edit
Report

1 Answer

14

For stuff like this I rely on the chronic library.

The Ruby code would be:

def date_of_next(day)
    Chronic.parse("next #{day}")
end
answered 2011-10-28T14:15:33.727

Your Answer