Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Apr 2016
    Posts
    9
    Member #
    53771

    Days between two dates

    I am new to website building and need some help! Thanks.

    I have the following script...

    Code:

    <script type="text/javascript">
    function GetDays(){
    var dropdt = new Date(document.getElementById("drop_date").value); /* Deliquency Date */
    var currentDate = new Date(document.getElementById("currentDate").value) ; /* Current Date */
    return parseInt((currentDate - dropdt) / (24 * 3600 * 1000));
    }
    function cal(){
    if(document.getElementById("drop_date")){
    document.getElementById("numdays2").value=GetDays( );
    }
    }
    </script>

    with this html code...

    Code:

    <div id="currentDate" class="date"><div class="item-cont"><p id="currentDate" >Current Date</p><script> document.write(new Date().toLocaleDateString()); </script></span></div></div></br>

    <div id="datepicker" class="element-date"><div class="item-cont"><input class="large" data-format="mm-dd-yyyy" type="date" id="drop_date" name="dropoff_date" onchange="cal()" placeholder="Delinquency Date"/></span></div></div>

    <div id="numdays"><label class="form">Days Deliquent:</label><input type="text" class="textbox" id="numdays2" name="numdays"/></div>

    when trying to calculate the days from the "drop_date" to the "currentDate" I get a NaN value diplaying in the "numdays" field.

    Like I said, very new to this.

    Any help would be much appreciated!!

  2.  

  3. #2
    Junior Member
    Join Date
    Apr 2016
    Posts
    9
    Member #
    53771
    Figured it out on a another forum. Problem solved!

  4. #3
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    Not sure if you're posting the solution, but one thing you'll want to consider is that people don't always post accurate dates in date fields. Or they do things like this: 28 OCT 2016. Your code doesn't take that into consideration.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by TheGAME1264 View Post
    Not sure if you're posting the solution, but one thing you'll want to consider is that people don't always post accurate dates in date fields. Or they do things like this: 28 OCT 2016. Your code doesn't take that into consideration.
    IIRC, the date input autoconverts to a standard date/time string.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:20 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com