user2206724
user2206724

Reputation: 1365

Rails: Increase date by one or for tomorrow

I know it is very very simple but am not getting how to do it.

end_time = Time.new(Date.today.year, Date.today.month, Date.today.day, 8, 00, 00).strftime("%H:%M:%S")

But in above code i want tomorrow instead of today i.e. '+1 day'. How can i do it?

I tried:

end_time = Time.new(Date.today.year, Date.today.month, Date.today.day, 8, 00, 00).strftime("%H:%M:%S") + 1.day

or

end_time = Time.new(Date.tomorrow.year, Date.tomorrow.month, Date.tomorrow.day, 8, 00, 00).strftime("%H:%M:%S")

But no use. Can anybody answer it?

Upvotes: 1

Views: 1973

Answers (2)

Dheeraj Maheshwari
Dheeraj Maheshwari

Reputation: 407

Simply you can use :-

end_date = Date.tomorrow

= date_field_tag :date_of_journey, end_date

Upvotes: 0

ferdyh
ferdyh

Reputation: 1445

In rails you can use : end_time + 1.day or 1.day.from_now

Added specific case:

if @order.delievery_time.between?(start_time, end_time + 1.day)
   @time = @order.delievery_time.strftime("%H:%M:%S")
end

Upvotes: 6

Related Questions