A
A
Alexander2016-08-13 13:02:26
ruby
Alexander, 2016-08-13 13:02:26

How to count the number of days off between two dates in Ruby?

Actually the subject, you need to calculate the number of Saturdays and Sundays between two dates

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Александр, 2016-08-13
@savio Автор вопроса

Возможно кому-то пригодится, пример
((Date.today - 14)..(Date.today) ).group_by(&:wday)[1].size

Александр Швайкин, 2016-08-13
@shurik_sh

Можно написать с помощью изящных руби методов

require 'date'

timerange = Date.parse('2016/01/01')..Date.parse('2016/08/13')
days = 0

timerange.each { |d| days += 1 if  d.sunday? or d.saturday? }

# days => 65

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question