User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,064 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,463 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1931 | Replies: 5
Reply
Join Date: Oct 2007
Posts: 77
Reputation: hidash_in has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 0
hidash_in hidash_in is offline Offline
Junior Poster in Training

how to calculate the days between two dates excluding saturday and sunday

  #1  
Dec 10th, 2007
how to calculate the days between two dates excluding saturday and sunday
foe example if i am calculating the days between 14/12/2007 to 17/12/2007
the answer for no of days should be 4...
pls send the code for above problem.
advance thanks
hidash.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 77
Reputation: hidash_in has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 0
hidash_in hidash_in is offline Offline
Junior Poster in Training

Help Re: how to calculate the days between two dates excluding saturday and sunday

  #2  
Dec 10th, 2007
how to calculate the days between two dates excluding saturday and sunday
foe example if i am calculating the days between 14/12/2007 to 17/12/2007
the answer for no of days should be 2...
pls send the code for above problem.
advance thanks
hidash.
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 368
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 35
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: how to calculate the days between two dates excluding saturday and sunday

  #3  
Dec 10th, 2007
var date1 = new Date();
var date2 = new Date();
var diff = new Date();

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

return (diff.getTime() / (1000 * 60 * 60 * 24));

theres the basics given that date1, date2 are the dates you wish to compare
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Oct 2007
Posts: 77
Reputation: hidash_in has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 0
hidash_in hidash_in is offline Offline
Junior Poster in Training

Re: how to calculate the days between two dates excluding saturday and sunday

  #4  
Dec 10th, 2007
it should be calculate only monday to friday and it should not calculate the saturday and sunday.
anyhow thanks funkus
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 368
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 35
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: how to calculate the days between two dates excluding saturday and sunday

  #5  
Dec 11th, 2007
well those were the basics which you should be able to adapt upon. for my efforts ive posted it up for all to see.

http://www.daniweb.com/code/snippet794.html
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 109
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: how to calculate the days between two dates excluding saturday and sunday

  #6  
Dec 17th, 2007
You can get it within +/- two days (no matter the length of the interval) just by integer-dividing the the output of the above formula by 7, and then multiplying by 5.

To refine it more, you need to know what day of the week each day is, and add or subtract up to two days, according to which days of the week each day is.

If the start and end dates are the same day of the week, no adjustment is needed.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 12:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC