Calculate date difference

Home Forums Quform WordPress Calculate date difference

This topic is: resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12710
    Nhus
    Participant

    Hello, I’ve followed the tutorial for calculations

    Calculations

    I’m trying to return the days difference between tow dates. This is the code I have got so far in the HTML element of my form:

    <div id=”form-total”></div>
    <script>
    jQuery(document).ready(function ($) {

    var startDate = new Date($(‘.iphorm_2_1’).val());
    var endDate = new Date($(‘.iphorm_2_2’).val());
    var diff = parseInt(startDate – endDate);

    var calculate = function () {
    var total = Number(diff);

    // Display the result to the user
    $(‘#form-total’).text(‘Total: $’ + total);

    };

    // Calculate on page load
    calculate();

    // Recalculate when these select menus are changed
    $(‘.iphorm_2_1’).change(calculate);
    $(‘.iphorm_2_2’).change(calculate);

    });
    </script>

    This is returning NaN, what am I doing wrong? Thanks in advance

    #12713
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #12714
    Nhus
    Participant

    Working good, thank you.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy