Count number of weekdays between two dates

Updated . Posted . Visible to the public.

If you need to quickly find out the number of weekdays (Monday to Friday) between to given dates, try this:

require 'date'
a = Date.parse "11.04.2014"
b = Date.parse "31.12.2014"

(a..b).count {|date| (1..5).include?(date.wday) }
Profile picture of Thomas Eisenbarth
Thomas Eisenbarth
Last edit
Thomas Eisenbarth
License
Source code in this card is licensed under the MIT License.
Posted by Thomas Eisenbarth to makandra dev (2014-03-19 11:36)