mickael mickael - 2 years ago 84
Ruby Question

Ruby: number of times a specific day of the month (eg. 1st of each month) occurs between two dates

I'm using ruby and I've got a doubt slightly different to what I've seen answered already.

I've got two dates (today and April next year) and I'd like to count the number of times a specific day, eg. 1st of each month, occurs between both (this date could be configurable, eg, day 15th of each month, etc).

Could you guys think of a way to achieve that in Ruby?

Answer Source
(Date.today..Date.parse('2018/04/01')).count { |d| d.day == 15 }
#⇒ 8
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download