Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 01:00 PM. Reason: forgot to put ddMMMMyyyy format

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •