Hi, someone very kindly posted some excellent code a few months ago which calculates the number of working days (Monday through to friday) between two inputted dates. Unfortunately it is for US dates and my javascript is not good enough to change the original code for UK date format (e.g. dd/mm/yyyy)
i have searched the web for many hours to no avail …. please could somebody help me to change this code so that it converts uk dates ..
[CODE]<HTML>
<Head>
<Script Language=JavaScript>
var nDay = new Array();
var i = 0;
function verify(isField){
splitDate = isField.value.split(“/”);
refDate = new Date(isField.value);
if (splitDate[0] < 1 || splitDate[0] > 12 || refDate.getDate() != splitDate[1] || splitDate[2].length != 4 || (!/^19|20/.test(splitDate[2]))){return false}
nDay[i++] = refDate.getDay();
return refDate;
}
function countDays(isForm){
isValid = true;
startDate = verify(isForm.nStart);
if (isValid){endDate = verify(isForm.nEnd)} else {endDate = false}
if (startDate && endDate)
{
daysApart = Math.round(((endDate-startDate)/86400000));
if (nDay[0] == 0 || nDay[0] == 6)
{isValid = false; startDate=false}
if (daysApart <= 0){isValid = false;endDate=false}
if (isValid)
{
workDays = daysApart-(parseInt(daysApart/7)*2);
if (daysApart < 7 && nDay[1] != 0 && nDay[0]-nDay[1] >= 1){workDays = workDays-2}
if (daysApart < 7 && nDay[1] == 0){workDays–}
isForm.nWork.value = workDays;
i = 0;
}
}
if (!startDate)
{
alert(‘Invalid Start Date.nStart Date must be a weekday.nStart Date must be earlier than End Date.’)
isForm.nStart.value = “”;
isForm.nStart.focus();
i = 0;
}
else if (!endDate)
{
alert(‘Invalid End Date.nEnd Date must be later than Start Date.’)
isForm.nEnd.value = “”;
isForm.nEnd.focus();
i = 0;
}
}
</Script>
</Head>
<Body>
<br>
<Form name=’Form1′>
<Table align=’center’ cellspacing=’0′ cellpadding=’5′ style=’font-size:14pt;border:solid black 1px;background-color:lightyellow;width:250px’>
<THead><TH colspan=’2′ style=’background-color:lightblue;border-bottom:solid black 1px’>Workdays Elapsed</TH></THead>
<TR><TD align=’left’>Start Date: </TD><TD align=’right’><input type=text size=9 name=’nStart’ onclick=”this.value=”;this.form.nWork.value=””></TD></TR>
<TR><TD align=’left’>End Date: </TD><TD align=’right’><input type=text size=9 name=’nEnd’ onclick=”this.value=”;this.form.nWork.value=””></TD></TR>
<TR><TD align=’left’>Workdays: </TD><TD align=’right’><input type=text size=9 readonly name=’nWork’></TD></TR>
<TR><TD colspan=’2′ align=’center’ style=’border-top:solid black 1px;background-color:darkorange’><input type=button value=’Calculate’ onclick=”countDays(this.form)”></TD></TR>
</Table>
</Form>
</HTML>