please suggest how to code the below scenario with javascript or jquery. I am trying to code a calculator that calculates the time between two dates excluding weekends i.e a task comes to the desk on Friday at 12.00am and ends on coming Tuesday 08:00 am. it should calculate the time between Friday and Tuesday excluding Saturday and Sunday. it should give o/p 56 hrs
1 3891 This will work: - var calcWorkHours = function calcWorkHours(start, end) {
-
var total = (end - start) / (1000 * 60 * 60 * 24), // compute difference in days
-
totalDays = parseInt(total, 10), // trim fractional portion
-
remainder = (total - totalDays) * 24, // save fractional portion in hours
-
startingDay = start.getDay(), // starting weekday
-
endingDay = end.getDay(), // ending weekday
-
possibleWorkingDays = (totalDays * 5),
-
actualOccurringWeekends = (startingDay - endingDay) * 2,
-
workDays = (possibleWorkingDays - actualOccurringWeekends) / 7;
-
if (endingDay === 6) {
-
workDays -= 1; // ends on a weekend, subtract a day
-
}
-
if (startingDay === 0) {
-
workDays -= 1; // starts on a weekend, subtract a day
-
}
-
return (workDays * 24) + remainder; // convert to hours and add back fractional portion
-
},
-
parseInputs = function parseInputs(date, hour, minute) {
-
var dmy = date.split("/"),
-
now = new Date(),
-
thisMinute = now.getMonth() + 1 + "-" + now.getDate() + "-" + now.getFullYear() + " " + now.getHours() + ":" + now.getMinutes() + ":00",
-
start = Date.parse(dmy[1] + "-" + dmy[0] + "-" + dmy[2] + " " + hour + ":" + minute + ":00"),
-
end = Date.parse(thisMinute);
-
start = new Date(start);
-
end = new Date(end);
-
return calcWorkHours(end, start);
-
};
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |
last post by:
Hello,
I am hoping someone else has thought about a date time calculation i need to
perform.
I would like to be able to calculate the number of "working minutes" between
2 dates, given my...
|
by: Totto |
last post by:
Hi,
Is ther a simple way to calculate number of hours in a date range. (dtFrom
as date , dtTo as date)
Had a look at timespan, but can's see that it's possible to add dates.
Tnx
Totto
|
by: seyed |
last post by:
how to get the difference between two dates ,excluding weekends in ms sql?
i using asp.net , if u all noe any other solution , please reply
|
by: deena22 |
last post by:
hello,
i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
|
by: brendanmcdonagh |
last post by:
Hi,
I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far.
She wants to be able to put start time, end time and lunch for each...
|
by: bsmeena7005 |
last post by:
Hi
help me to calculate the working hours between 10 to 18 hrs between two dates
including the weekends also no braek or lunch time
Example :-
start date #01-08-2009 08:45:23#
end date ...
|
by: nilanjangm |
last post by:
I am using Access 2007. In a table, I have two columns say Start_Date and End_Date of datatype Date/Time (Short Date).
Now, I want to calculate the duration of work in that period assuming 8 hours...
|
by: ssoni |
last post by:
hi,
I am new to sq server, and
I want to calculate the total working hours for all the employees excluding their break. This is the sample table for 2 employes.
logID logDate logTime...
|
by: wirejp |
last post by:
Hi All,
I am using MS Access 2010. I am working out each member of staffs working hours for the month in a MS Access query.
minus a 1 hour lunch.
I would like to display the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |