user6589814 user6589814 - 2 months ago 10
Ruby Question

Ruby on Rails - find Next and previous date based on param

I have added

activity_logs
to my application and I show
@activities
based on giving
param_date
to url.

My link/path looks like:

http://localhost:3000/users/activity_logs?param_date=2016-09-12
.

I do much like to add Next day & Previous day on same page. How can I find the Next day & Previous day based on the date I have on
param_date
.

Ex:
= link_to 'Next day', activity_logs_path(param_date: date)


So basically if
param_date
is 2016-09-30, Next Day would be: 2016-10-01 and Prev day: 2016-09-29

Answer

try this:

prev_data = (Date.parse(params[:param_date]) -1).strftime('%F')
next_data = (Date.parse(params[:param_date]) +1).strftime('%F')
Comments