Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-23-2009, 11:58 AM   PM User | #1
vinodkoti
New to the CF scene

 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vinodkoti is an unknown quantity at this point
Unhappy "ddMMMyyyy" format date differences in no.of days..

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...

Last edited by vinodkoti; 12-23-2009 at 12:00 PM.. Reason: forgot to put ddMMMMyyyy format
vinodkoti is offline   Reply With Quote
Old 12-23-2009, 01:47 PM   PM User | #2
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:02 AM.


Advertisement
Log in to turn off these ads.