Using date picker to add years, months or days

Home Forums Quform WordPress Using date picker to add years, months or days

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

    I am using a date picker to establish a date, with this date I want to add, depending of a radio button value, a year, a month or a two month

    I have tried with this
    $(‘.quform-field-39_14’).change(function (){
    var $datefield = $(‘.quform-field-39_14′);
    var fecha = new Date($datefield.val());
    var fechaV = calculoFechaVencimiento(fecha,’annio’);
    // var fechaVencimiento = new Date(fecha.getFullYear(),11,31);
    // var fechaCadena = calculoFechaVencimiento(fecha,’annio’).toISOString().slice(0,10);
    var fechaCadena = fechaV.toLocaleDateString(‘en-GB’);
    $(‘.quform-field-39_580’).val(fechaCadena);
    });

    function calculoFechaVencimiento(fecha,periodo){
    if (periodo == ‘annio’){
    var dia = fecha.getDate();
    var mes = fecha.getMonth()+1;
    var annio = fecha.getFullYear();
    var fechaVencimiento = new Date(annio,mes,dia);
    } else if (periodo == ‘bimestre’) {
    var fechaVencimiento = new Date(fecha.getFullYear(),fecha.getMonth()+1,fecha.getDate());
    } else if (periodo == ‘mes’) {
    var fechaVencimiento = new Date(fecha.getFullYear(),fecha.getMonth()+1,fecha.getDate());
    }

    return fechaVencimiento;

    }

    The problem is that for example I pick this date: “8/2/2022” (is is day/month/format) the result is “02/09/2022” which seems to convert the d/m/y format to a m/d/y format and is adding 1 day. The original date is february 8th, 2022 (8/2/2022), if I add a month I must get march 8th, 2022 (8/3/2022), but instead I am getting september 2nd, 2022 (9/2/2022).
    Thanks in advance for your help

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

    #33969
    oivanr
    Participant

    Dear Ally,
    I made some changes, but your code works perfectly. Thanks a lot
    Regards,
    Omar

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