Calculating business day

I want calculate the number of business day for the current month, but I
don't know how I skip the holidays and weekends.

Could anyone help me with this?

Thanks

Holidays you need to have defined somewhere, as they probably vary
depending on the business you are dealing with at the time (Government
versus private industry, etc).

A brute force method would be to get the dates for the start of the
month, the end of the month and step through the month from start to end
by day.

Check the day of the week for each date. Saturday or Sunday and it's
out. Match one of your holidays, and its out.

What's left are your business days.

For the holidays you are going to need to store them somewhere as was
already pointed out in another post since they might even vary by
company. Calculating the weekend days should be easy using the
extended functionality for dates that Rails offers. You can check the
ActiveSupport::CoreExtensions::DateTime::* and
ActiveSupport::CoreExtensions::Date* modules for that.

Good luck.

Sorry, I should also have added to take a look at
ActiveSupport::CoreExtensions::Numeric::Time, which allows something
like 1.week.from_now, 1.week.ago, etc.

Thanks for all help.

Finally, I could take out all the holidays. It is hard for holidays that change every year.

We use a table of holidays here…

So take your two dates…

Decide how many days are between them
(You can just subtract the two date objects)

Subtract how many weekend days are present between the two dates…

Subtract select count(*) from holidays where date <= begin and date => end

Theres not much else out there thats pre-built…

Look guys, I found a way to discover the holidays.

Visit the site: code.dunae.ca/holidays

have a gem holidays, this helped me a lot, and I just want share this information that I founded.