Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails function for this

I would like to have a function which get start_day and end_day as two string type parameter and returns the list of dates inside the specified date span including start and end days, anyone can provide a efficient code block?

def get_list_of_dates(start_date, end_date)
  ...
  return dates
end
like image 980
Mellon Avatar asked Mar 22 '11 14:03

Mellon


1 Answers

def get_list_of_dates(start_date, end_date)
  (Date.parse(start_date)..Date.parse(end_date)).to_a
end

If Date.parse doesn't accept the string (it doesn't accept many formats), you may want to check out chronic.

like image 83
idlefingers Avatar answered Sep 22 '22 05:09

idlefingers