Number of workdays between two dates

It is pretty simple to get number of work days between two dates. For example we can get the number of workdays in this month.

  start_date = Date.civil(2010, 8, 1)
  end_date = Date.civil(2010, 8, 31)
  workdays = (start_date..end_date).select { |day| ![0, 6].include?(day.wday) }.size

Please note that this doesn’t include any check for holidays, you’ll need to figure that yourself (if you have need for that at all).

For more info see Array#select and Date#wday methods.

3 thoughts on “Number of workdays between two dates

  1. It’s not that smart šŸ˜‰ but some simple solution shouldn’t be hard to do.

    holidays = [date1, date2, date3, …]
    !(holidays.include?(day) or [0, 6].include?(day.wday))


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s