Counting Days Excluding Weekends

How to count number of days after excluding weekends using js

try this :

var startDate = "14-SEPT-2021";
startDate = new Date(startDate.replace(/-/g, "/"));
var endDate = "", noOfDaysToAdd = 10, count = 0;
while(count < noOfDaysToAdd){
endDate = new Date(startDate.setDate(startDate.getDate() + 1));
if(endDate.getDay() != 0 && endDate.getDay() != 6){
count++;
}
}
alert(endDate);//You can format this date as per your requirement

How to count days excluding weekends and holidays but start day/end day can be weekends /holidays?

Try using NETWORKDAYS.INTL to make sure that your weekend days are set to fall on Saturdays and Sundays.

For example:

=NETWORKDAYS.INTL(E2+1,F2-1,1,$H$2:$H$3)

Result:

Sample Image

How to count date difference excluding weekend and holidays in MySQL

You might want to try this:

  1. Count the number of working days (took it from here)

    SELECT 5 * (DATEDIFF('2012-12-31', '2012-01-01') DIV 7) + MID('0123444401233334012222340111123400012345001234550', 7 * WEEKDAY('2012-01-01') + WEEKDAY('2012-12-31') + 1, 1)

    This gives you 261 working days for 2012.

  2. Now you need to know your holidays that are not on a weekend

    SELECT COUNT(*) FROM holidays WHERE DAYOFWEEK(holiday) < 6

    The result of this depends on your holiday table.

  3. We need to get that in one query:

    SELECT 5 * (DATEDIFF('2012-12-31', '2012-01-01') DIV 7) + MID('0123444401233334012222340111123400012345001234550', 7 * WEEKDAY('2012-01-01') + WEEKDAY('2012-12-31') + 1, 1) - (SELECT COUNT(*) FROM holidays WHERE DAYOFWEEK(holiday) < 6)

    This should be it.

Edit: Please be aware that this only works properly if your end date is higher than your start date.

Count days from the beginning of current month to date excluding weekends

You may build up an array of Dates and check for desired day (not to be Saturday or Sunday):

const workdaysCount = () => 
[...new Array(new Date().getDate())]
.reduce((acc, _, monthDay) => {
const date = new Date()
date.setDate(1+monthDay)
![0, 6].includes(date.getDay()) && acc++
return acc
}, 0)

console.log(workdaysCount())

counting working days without counting weekends as workdays in php

There are plenty of solutions here: Calculate business days , Day difference without weekends for php, using arrays, recursion, numbering

Counting days excluding weekends

Here's a snippet of code to find the number of weekdays in a Range of Date objects

require 'date'
# Calculate the number of weekdays since 14 days ago
p ( (Date.today - 14)..(Date.today) ).select {|d| (1..5).include?(d.wday) }.size

This is how I would use it in your case.

class Product
def days_late
weekdays_in_date_range( self.due_date..(Date.today) )
end

protected
def weekdays_in_date_range(range)
# You could modify the select block to also check for holidays
range.select { |d| (1..5).include?(d.wday) }.size
end
end


Related Topics



Leave a reply



Submit