Read more

Count number of weekdays between two dates

Thomas Eisenbarth
March 19, 2014Software engineer at makandra GmbH

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) }
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot
Posted by Thomas Eisenbarth to makandra dev (2014-03-19 12:36)