I tried using answers for this question but was not able to get something that worked.
I want to be able to loop through days, starting today and going up to a target date set for an object.
The target date is of type Date
.
I have tried a few things, all variations on the answers above, this was last attempt.
count = 0
Time.now..goal.target_date do
count += 1
end
This does not loop through anything and returns 0 as the count. Right now this is only in dev, with one object, so I know there are many days between now and the target (which is set for December 31 of this year).
I also tried this.
count = 0
Date.new(Time.now)..goal.target_date do |date|
count += 1
end
Which returns the error undefined method 'div' for 2018-10-06 17:23:41 -0500:Time
. (Same error if I use Date.today
just with :DATE
instead of :Time
at the end).
Can anyone help me get this to run the loop for each day between now and the target date?
Thanks!