Good afternoon everyone,
I would like your valuable help to be able to do a function that adds me the days to any date entered by the user, I have been looking for a good time on the web but the only thing that appears is to add days to the current date,
By clicking on the input datepicker, add me 122 or 125 days depending on the length of the format. The problem I have is that when I want to capture the date that the user entered I appear Tue Mar 24 2015 18:00:00 GMT-0600 (Central America Standard Time) so when I want to format the date it tells me that the function getDate (_) it is not valid
My code at the moment is this:
function sumDias(fecha, numDias) {
fecha.setDate(fecha.getDate() + numDias);
return fecha;
};
function zero(n) {
return (n > 9 ? '' : '0') + n;
};
$("#date1_record").on("change", function() {
var id_format = $("#id_format_record").val();
var id_format_array = id_format.split('-');
var id_format = id_format_array[1];
var numDias = parseInt(id_format);
alert(numDias);
if (isNaN(numDias)) {
$('#date2_record').text('');
return;
}
var fecha = document.getElementById('date1_record').value;
var fechaActual = new Date(fecha);
//var fechaActual = fechaActual0.getFullYear() + "-" + zero(fechaActual0.getMonth()+1) + "-" + zero(fechaActual0.getDate());
alert(fechaActual);
var fechaCalculada = sumDias(fechaActual, numDias);
$('#date2_record').text(fechaCalculada.toString());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-2">
<label for="date1_record" title="Fecha Ingreso"><h6><strong>*Fecha Inicio</strong></h6></label>
<input id="date1_record" type="text" class="form-control date" style="margin-bottom: 10px">
</div>
<div class="col-md-2">
<label for="date2_record" title="Fecha Ingreso"><h6><strong>*Fecha Final</strong></h6></label>
<input id="date2_record" type="text" class="form-control date" style="margin-bottom: 10px" disabled>
</div>
Your help please ... !!