Good morning everyone. I have a little problem formatting a date.
I would like to make sure, with Javascript, that today's date is shown by default in an html <input type="date>"
in this format: "dd-mm-yyyy"
.
I managed to do this by changing the input to <input type="text">
, the problem is that this way the automatic date picker that exists when the input is <input type="date">
no longer works.
So I would like to keep the <input type="date">
to keep the default datepicker, but show the default date same as today's, in this "dd-mm-yyyy"
format.
How can I do? Thanks a lot to everyone. Forgive my bad English.
I tried with this portion of code:
let today= new Date();
let day = oggi.getDate();
let month = oggi.getMonth() + 1;
let year = oggi.getFullYear();
if(day < 10) giorno = '0' + giorno;
if(month < 10) mese = '0' + mese;
let formattedDate = day + '-' + month + '-' + year;
document.getElementById('DATE').value = formattedDate;
now this code function only if the input type in html is <input type="text">
, unfortunately in this way, the datepicker present when input <input type="date">
is not displayed.
If i change the html <input type="date">
, the default today date doesn't be shown on the input that remains empty.
Thanks again.