473,696 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate the number of WEEKDAYS between 2 dates?

Help needed for a Javascript beginner.

As above in the subject... i need a javascript to run this, but not in
the form of a web-page. I want to calculate it between 2 fields in a
database that i have extracted into a report writer.
Look forward to hearing..

Cheers...
SimonC

Jul 23 '05 #1
5 6732
SimonC wrote:
Help needed for a Javascript beginner.

As above in the subject... i need a javascript to run this, but not in
the form of a web-page. I want to calculate it between 2 fields in a
database that i have extracted into a report writer.
Look forward to hearing..

Use the mySQL(or whatever) maths and date functions.
Mick
Jul 23 '05 #2
"SimonC" <si******@yahoo .co.uk> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Help needed for a Javascript beginner.

As above in the subject... i need a javascript to run this, but not in
the form of a web-page. I want to calculate it between 2 fields in a
database that i have extracted into a report writer.
Look forward to hearing..

Cheers...
SimonC


Is VBScript an option? If so, look at "DateDiff() ".

Cut-and-paste the following into an IE Address bar:

vbscript:DateDi ff("d",#01/01/2005#,#01/26/2005#)
Jul 23 '05 #3
JRS: In article <EJ************ ********@comcas t.com>, dated Tue, 25 Jan 2005
12:43:05, seen in news:comp.lang. javascript, McKirahan <Ne**@McKirahan .com>
posted :
"SimonC" <si******@yahoo .co.uk> wrote in message
news:11******* **************@ f14g2000cwb.goo glegroups.com.. .
As above in the subject...


You could have copied it. Do not presume that the Subject line is readily
visible when the Body is being read. It is:
Calculate the number of WEEKDAYS between 2 dates?

i need a javascript to run this, but not in
the form of a web-page. I want to calculate it between 2 fields in a
database that i have extracted into a report writer.
Look forward to hearing..
Is VBScript an option? If so, look at "DateDiff() ".

Cut-and-paste the following into an IE Address bar:

vbscript:DateD iff("d",#01/01/2005#,#01/26/2005#)


It would help if you were both to read and understand the question
before answering. Your code gives me 25.

The OP is posting from the UK; he cannot be expected to want FFF dates.

The difference in those dates is 25 days.
There are 24 days between those dates.
There are 17 weekdays between those dates, or 18 inclusive (Sat..Wed).

You could have answered with corresponding javascript:
javascript:Math .round((new Date("2005/01/26")-new Date("2005/01/01"))/864e5)
also gives 25 from the address bar.

You do not need DateDiff :
vbscript:CDate( #01/26/2005#)-CDate(#01/01/2005#)
and indeed vbscript:#01/26/2005#-#01/01/2005#
give 25 too.
The OP can find what he needs in js-date7.htm, via FAQ; see below.
He will have to consider the meaning of "between".

Alternatively, the following method will do well enough for short
intervals (adapt for desired end-effects) :

D = new Date("2005/01/01")
E = new Date("2005/01/26").setHours(1 2)
N = 0
while (D<E) {
if (D.getDay()%6!= 0) N++
D.setDate(D.get Date()+1)
}
N
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
Dr John Stockton wrote:
[...]
The OP can find what he needs in js-date7.htm, via FAQ; see below.
And the request for "weekdays" suggest business days, which are
affected by public holidays. Therefore reference to a calendar
may be required.

Allowing for international (or even interstate) variances
suggests some serious issues with attempting to accurately count
the number of business or working days.
Alternatively, the following method will do well enough for short
intervals (adapt for desired end-effects) :

D = new Date("2005/01/01")
E = new Date("2005/01/26").setHours(1 2)
N = 0
while (D<E) {
if (D.getDay()%6!= 0) N++
D.setDate(D.get Date()+1)
}
N


Neat accommodation of Sunday being day zero. Then again, the
test would be even simpler if Monday was zero...

--
Fred
Jul 23 '05 #5
JRS: In article <vP************ *****@news.optu s.net.au>, dated Thu, 27
Jan 2005 01:52:27, seen in news:comp.lang. javascript, Fred Oz
<Oz****@iinet.n et.auau> posted :
Dr John Stockton wrote:
[...]
The OP can find what he needs in js-date7.htm, via FAQ; see below.
And the request for "weekdays" suggest business days, which are
affected by public holidays. Therefore reference to a calendar
may be required.


Since the OP was posting from UK, I took him to mean what he wrote.
Allowing for international (or even interstate) variances
suggests some serious issues with attempting to accurately count
the number of business or working days.
Interstate - what's that? <g>

But, at least in the UK, there are some things for which Mon-Fri differs
from Sat,Sun without being affected by holidays. For example, my
preferred Internet dial-up number currently works all day Sat,Sun but on
other days not between 08:00 & 18:00 - and that is totally unaffected by
Christmas Day and other holidays.

if (D.getDay()%6!= 0) N++

Neat accommodation of Sunday being day zero.
Available to all who read the newsgroup FAQ with care; as is stuff on
allowing for holidays.
Then again, the
test would be even simpler if Monday was zero...


Or if Sunday were seven, as called for by ISO 8601.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8055
by: Tiernan | last post by:
Hi all I'm looking for a way to find the number of weekdays between 2 dates In my form I have three fields for a begin date (dd)(mm)(yyyy) and three for the end date (dd)(mm)(yyyy) Now these values will be stored into a database and at the same time there will be an e-mail generated and send to me that contains the starting date en the end date . But now I want an extra line in this e-mail that tells me howmany days there are between the...
2
4742
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the form has Two textboxes to enter dates From Date - Fdate To Date - TDate
3
3116
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 working week definition. Lets say I have a working week definition of Monday through Friday, 9 am to 5 pm. Date1 = January 1st, 2005 at 8 am
1
2938
by: Chris Hill via .NET 247 | last post by:
Hi I'm a jnr developer in need of desparate help. Can anyone point me in the right direction for this problem: I calculate the number of days between 2 user defined dates like this: Dim DaysInRange As Long DaysInRange = DateDiff("d", Me.dtp_firstdate.Text, Me.dtp_lastdate.Text) + 1 mod_rptStaffCaseloadAnalysis.p_numDaysInSelectedPeriod = DaysInRange
3
18085
by: George | last post by:
Can someone tell me how to calculate the number of weeks between two dates. Your help is appreciated. Thanks, George
6
8051
by: Tom | last post by:
Hello, please help me, I need two write a C++ program that can calculate the number of days between two dates.
4
2002
by: MLH | last post by:
I'm thinking of an integer field in which I could write values up to 1+2+4+8+16+32+64 and to use these values later. Each of the individual values would represent a weekday from Sunday to Saturday. So if I were to look at a record for a newspaper publication and see 9 in the field, I could interpret that as meaning the publication was released on Sundays (1) and Wednesdays (8). A value of 127 would indicate a daily paper publishing...
2
1947
by: Mike | last post by:
Is there a way to calculate the total number of weekdays when provided a date? Example: If I have a start date of 7/11/2008 and I want to go out 10 days, I want to get this: 6 weekdays 4 weekend days
1
7208
by: bharathreddy | last post by:
This article will explain how we can get the count of weekdays in between two dates. This will be usefull if we want to count the number of working days between two dates. Example: ------------- USE GO --This function is used to count the number of weekdays between -- two dates. create function udf_Weekdays(@Weekday,@BeginDate datetime,@EndDate datetime) returns integer
0
8666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9010
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8880
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1992
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.