• Resolved pexel

    (@pexel)


    Hello,

    Is there a function that allows the user to select a date and time, and then shows the time difference between the selected date and today in days, hours, minutes, and seconds? Additionally, this would be displayed as a live countdown timer.

    Is such a function available? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    Yes, you can use the DATEDIFF and NOW operations. Assuming the date/time field in the form is the fieldname1 field, you can insert a calculated field ( I’ll call it fieldname2 ) and enter an equation similar to:


    (function(){
    if ( typeof my_timout_identifier != 'undefined' ) clearTimeout( my_timout_identifier );

    my_timout_identifier = setTimeout( function(){ EVALEQUATION(fieldname2|n); }, 1000 );

    let o = DATEDIFF(NOW(), fieldname1, 'yyyy/mm/dd hh:ii', 'd');

    return CONCATENTATE(o['days'], ' days ', o['hours'], ' hours and ', o['minutes'], ' minutes');
    })()

    Best regards.

    Thread Starter pexel

    (@pexel)

    fieldname5: Today’s date (day/hour/minute/second)
    fieldname6: Target date (day/hour/minute/second)

    However, it calculates the duration but does not count down. Could there be a mistake somewhere?
    Additionally, if the user selects a past date, is it possible to give a warning message for the countdown?
    Thank you!

    (function() {

    if (typeof my_timeout_identifier !== 'undefined') {
    clearTimeout(my_timeout_identifier);
    }

    my_timeout_identifier = setTimeout(function() {
    EVALEQUATION(fieldname5 | n);
    }, 1000);


    let o = DATEDIFF(fieldname5, fieldname6, 'yyyy/mm/dd hh:ii:ss', 'd');


    let kriter5 = CONCATENATE(o['days'], ' gün ', o['hours'], ' saat ', o['minutes'], ' dakika ', o['seconds'], ' saniye');

    jQuery('#calculation-kriter5').html(kriter5);
    jQuery('.kriter5-aciklama').html('Saya? :');
    jQuery('.kriter5-sonuc').html(kriter5);

    return kriter5;
    })();
    Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    First, you cannot include extra space characters.

    The correct is fieldname5|n but you entered fieldname5 | n

    Second, you must evaluate the current equation, not the equation in the fieldname5 fields. Also, you don’t need a field extra to get the current date/time, only use the NOW operation.

    Best regards.

    Thread Starter pexel

    (@pexel)

    I fixed the code, and it prints the result. Every time we click ‘calculate,’ it prints the updated result. I wanted it to count down live after clicking ‘calculate’ just once.

    Here’s the form link.

    (function() {

    if (typeof my_timeout_identifier != 'undefined') {
    clearTimeout(my_timeout_identifier);
    }

    my_timeout_identifier = setTimeout(function() {
    EVALEQUATION(fieldname5|n);
    }, 1000);


    let o = DATEDIFF(NOW(), fieldname6, 'yyyy/mm/dd hh:ii:ss', 'd');


    let kriter5 = CONCATENATE(o['days'], ' gün ', o['hours'], ' saat ', o['minutes'], ' dakika ', o['seconds'], ' saniye');

    jQuery('#calculation-kriter5').html(kriter5);
    jQuery('.kriter5-aciklama').html('Saya? :');
    jQuery('.kriter5-sonuc').html(kriter5);

    return kriter5;
    })();
    Thread Starter pexel

    (@pexel)

    I got it done, thanks

    Plugin Author codepeople

    (@codepeople)

    Hello @pexel

    The calculated field in your form is not the fieldname5. So the code EVALEQUATION(fieldname5|n); makes no sense. You must enter the name of the calculated field where you entered the equation. Please reread my previous entries.

    Please note the plugin support does not cover the implementation of the users’ projects. If you need someone to implement your form equations, contact us through the plugin website. Contact Us

    Best regards.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.