0

I found code example for finding the start and end day of the current month I'm in. I tried to jump start this code, but am having a hard time figuring out what I have gone wrong.

month = params[:month].to_i
date_start = DateTime.new Date.today.year, params[:month], 1
date_end = (date_start >> 1) + 1  # will add a month and a day
@trips = Trip.all :date => date_start..date_end

I'm not 100% sure what to feed into params. Hope someone can help.

Community
  • 1
  • 1
calabi
  • 283
  • 5
  • 18

2 Answers2

1

I am not sure if I understand your question correctly, maybe what you need is this? :

month = 9
date_start = Date.new(Time.now.year, month, 1)
date_end = date_start.next_month - 1
Francisco Soto
  • 10,277
  • 2
  • 37
  • 46
0

params should contains month(numeric) i.e between 1 - 12

For e.g params = {:month => '4'}

Also in second line use month instead of params[:month]

Manish
  • 111
  • 4