Home › Forums › Quform WordPress › Using date picker to add years, months or days
- This topic has 2 replies, 2 voices, and was last updated 2 years, 9 months ago by oivanr.
- AuthorPosts
- February 4, 2022 at 7:23 am #33966oivanrParticipant
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 helpFebruary 4, 2022 at 9:56 am #33968AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
February 4, 2022 at 6:17 pm #33969oivanrParticipantDear Ally,
I made some changes, but your code works perfectly. Thanks a lot
Regards,
Omar - AuthorPosts
- You must be logged in to reply to this topic.