PDA

View Full Version : "ddMMMyyyy" format date differences in no.of days..



vinodkoti
12-23-2009, 11:58 AM
Hi folks...
I have written javascript to calculate date differences in days. it accepts value in ddMMMMyyyy format and should display i result in days...but it's validating the date but not calculating the days...any body suggest me to complete the task... my code is below...

<script type="text/javascript">
function IsValidDate(myDate)
{
var filter = /^([012]?\d|3[01])-([Jj][Aa][Nn]|[Ff][Ee][bB]|[Mm][Aa][Rr]|[Aa][Pp][Rr]|[Mm][Aa][Yy]|[Jj][Uu][Nn]|[Jj][u]l|[aA][Uu][gG]|[Ss][eE][pP]|[oO][Cc]|[Nn][oO][Vv]|[Dd][Ee][Cc])-(19|20)\d\d$/

return filter.test(myDate);
}
function test()
{
var txtTest = document.getElementById('firstID') && ('SecondID');
var isValid = IsValidDate(txtTest.value);
if (isValid)
{
alert('Correct format');
}
else
{
alert('Incorrect format');
}
return isValid
}

function getDateDiff()
{
if(document.getElementById('firstID').value!="" && document.getElementById('SecondID').value!="")

{
var FirstDate = document.getElementById('firstID').value

var SecondDate = document.getElementById ('SecondID').value
var DateDifference = Date.parse(FirstDate) - Date.parse(SecondDate);
if(DateDifference<0)
{

alert("Please enter correct date... 'The Date Of Closure' cannot be less than 'the Potential Start Date' ");
document.getElementById('differenceID').value="";
}
else
{
var days=Math.ceil(DateDifference/86400000);

document.getElementById('differenceID').value=days;
}
}
}
</script>

thanks in advance...

tomws
12-23-2009, 01:47 PM
You're not using a Javascript framework for this, so it would have been better placed in the Javascript forum.

In your posted code, you're not calling getDateDiff anywhere. That's where the calculation takes place.