Answer the question
In order to leave comments, you need to log in
How not to count weekends?
That is, there is a date, let's say 05/17/2015 15:15, I need to calculate how many hours have passed since that time, but not including weekends (you need to count only from Monday to Friday + do not include days that are marked as weekends (in a separate variable).
Answer the question
In order to leave comments, you need to log in
This script rounds up, but this can be quickly corrected.
var now = Date.now(); // от сейчас
var start = new Date("2015-04-21 20:18").valueOf(); // скармливаем дату в нормальном формате, либо пишите свой парсер
var hours = 0;
while (now > start) {
if (new Date(start).getDay() < 6) // если это не выходной, здесь же можно проверять на праздничные дни
++hours;
start += 1000*60*60;
}
alert(hours + "часов");
var now = moment();
var start = moment("2015-04-21 20:18", "YYYY-MM-DD HH:mm");
var hours = 0;
while (now.isAfter(start)) {
if (start.isoWeekday() < 6)
++hours;
start.add(1, 'hour');
}
alert(hours + "часов");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question