Good day to all, could you please guide me on what happens in this problem?
Basically what I'm trying to do is put a maximum date to a DatePicker which will be 1 day more than today's date; that is to say tomorrow.
The problem is that if we are on the 31st day of a month, the maximum will be "32". Or in months with only 30 days, it will show "31" as the next day.
I would like to know if it is possible to make it detect it if it is the end of the month and throw me the first day of the following month.
That is to say: Today is December 31, 2021, tomorrow will be January 1, 2022. I really appreciate your help. :)
function fecha(){
var d = new Date();
var month = d.getMonth()+1;
$('[type="date"]').prop('max', function(){
var currentDate = new Date();
var ol = currentDate.getDate();
days = 1;
var fechs = currentDate.getFullYear() + '-' + (ol<10 ? 0 : '') + month + '-' + (ol<10 ? 0 : '') + (currentDate.getDate() + days);
console.log(fechs);
return fechs;
});
var day = d.getDate();
window.output = d.getFullYear() + '-' +
(month<10 ? 0 : '') + month + '-' +
(day<10 ? 0 : '') + day;
$('[type="date"]').prop('min', function(){
return output;
});
console.log(output);
};
input[type=date] {
margin: 0 auto;
width: 170px;
font-size: 15px;
border-radius: 3px;
background-color: #fff;
border: 2px solid #0faad1;
}
<body onload="fecha();">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css?n=1">
<label for="Fecha"><span style="color: red;">* </span>
<i class="far fa-calendar-alt"></i> Fecha: <input type="date" id="fecha" value="Seleccione Fecha" name="Fecha" min="new Date();" max="2021-12-31" required data-msg="Ingrese la fecha a reservar.">