calculate the date difference between two dates exclude the saturday and sunday(Please dont calculate saturday and sunday between two dates)

Recommended Answers

All 12 Replies

Hang on... Are you telling us to do it for you? The whole *point* of this fourm is to *HELP* out with problems not do your work for you!

Ok ok Sorry is there any code for calculate the date difference between two dates with out calculating the saturday and sunday.is there any code means please send to me.

Advance Thanks

A Loop, counter, an if statement, a Calendar and its add(int, int) and get(int) methods, and its day of the week named constants.

Read the API docs for Calendar, then try to whip something up based on the above, and if it doesn't work, post it, and we'll help you to correct it.

Hi
I applied but i can't get the answer please can you send example program codes
Please help me

Advance Thanks

Well, lets see what you have.

pseudo code

counter
current date = start date  // current date is a Calendar object however
while (current date less than end date)
  increment counter
  add one to current date

Forgot to mention that you will also need compareTo from the Date class (and the if is not needed when done this way).

Hi dont mistaken me,i know the logic but some problem occur so you please send to the example code

why don't you post your code here?

Hi dont mistaken me,i know the logic but some problem occur so you please send to the example code

Well, like I said

Well, lets see what you have.

I am not simply going to post the code here, without you having proven that you have already tried it. From What I see here, you are simply trying to get someone else to do this for you.

var StartDate=document.empdetails.Emp_CompOffDate.value;
// alert("CompOff Date"+Emp_CompOffDate);
var EndDate=document.empdetails.Sysdate.value;
//alert("Sysdate"+Sysdate);
var laterdate = new Date(StartDate); // 1st January 2000
var earlierdate = new Date(EndDate); // 13th March 1998
var difference = earlierdate.getTime() - laterdate.getTime();earlierdate
var aa=document.empdetails.aa.value;
// alert("aa"+aa);
var daysDifference = Math.floor(difference/1000/60/60/24);
// alert("daysDifference"+daysDifference);
var bb=document.empdetails.bb.value;
// alert("bb"+bb);
var b = parseInt(daysDifference)+1;
document.empdetails.aa.value=b;
difference -= daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference -= hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference -= minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);


[B]I tried this concept but it calculates with saturday and sunday but my expect output is without calculate the saturday and sunday[/B]

So you please help me

Advance thanks

Of course it does. Try with a calendar and simply count the days. You can use an if statement so that you don't increment on Sa and So. Try to implement that pseudo code with a small change

counter
current date = start date  // current date is a Calendar object however
while (current date less than end date)
  if current date not sa/so increment counter
  add one to current date

Read the API for Calendar/GregorianCalendar

I already listed the methods you will need, and if you look at the "constants"/fields defined by Calendar, you will easily see which ones you need to use in the methods and in the if statement.

Edit: Try this, and if it doesn't work, post that code and we will help you correct it. The code you posted, will never be able to adequately account for "skipped" days. It would be able to approximate them, but never really acount for them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.