code to calculate the number of days between two dates
Answers were Sorted based on User's Feedback
Answer / nikhil
<script language="javascript">
Date.prototype.DaysBetween = function()
{
var intMilDay = 24 * 60 * 60 * 1000;
var intMilDif = arguments[0] - this;
var intDays = Math.floor(intMilDif/intMilDay);
return intDays;
}
var d1 = new Date("06/01/2008");
var d2 = new Date("07/31/2008");
alert(d1.DaysBetween(d2));
var d3=d1.DaysBetween(d2);
document.write(d3);
</script>
Is This Answer Correct ? | 8 Yes | 6 No |
Answer / nagaraj
function getDaysMinusWeekend(startDay, startMonth,
startYear, endDay, endMonth, endYear) { var sdate = new Date
(); var edate = new Date(); var odays = 0; var total =
0; sdate.setFullYear(startYear,startMonth,startDay);
edate.setFullYear(endYear,endMonth,endDay);
odays = 6 - sdate.getDay(); if(odays == 6) {
odays = 0; } sdate.setFullYear
(startYear,startMonth,startDay + odays); return
Math.floor(((((edate.getTime() - sdate.getTime()) / 1000 /
60 / 60 / 24) / 7) * 5) + odays);}// ########## startMonth
and endMonth both start at 0 i.e 0 = january, 1 = feb etc
function getDaysMinusWeekend(startDay, startMonth,
startYear, endDay, endMonth, endYear) {
var sdate = new Date();
var edate = new Date();
var odays = 0;
var total = 0;
sdate.setFullYear(startYear,startMonth,startDay);
edate.setFullYear(endYear,endMonth,endDay);
odays = 6 - sdate.getDay();
if(odays == 6) {
odays = 0;
}
sdate.setFullYear(startYear,startMonth,startDay +
odays);
return Math.floor(((((edate.getTime() -
sdate.getTime()) / 1000 / 60 / 60 / 24) / 7) * 5) +
odays);
}
Is This Answer Correct ? | 4 Yes | 6 No |
how to create Expandable and Collapsible Menus
create Drop-Down Navigation Menus
code to sorting an array of objects
snippet to prevent submission of form when certain/any validations got failed
sample code to auto focusing the first field in a form
How to Add Message and Confirmation Boxes Using JavaScript?
how to get the User's Time of Day
code to images to rollover
code to calculate the number of days between two dates
write a program segment that will ask the user if he wants to computer the perimeter of the area of the triangle. if the perimeter is wanted, ask the measure of the three sides and compute for the perimeter. if the area is wanted, ask for the measures of the base and height and compute for the area. display the computed value
How to block double clicks
Code for Adding Message and Confirmation Boxes Using JavaScript?