I am wondering whether it is possible to set the date format in the html <input type="date"></input>
tag... Currently it is yyyy-mm-dd, while I need it in the dd-mm-yyyy format.
The <input type="date"> defines a date picker. The resulting value includes the year, month, and day. Tip: Always add the <label> tag for best accessibility practices!
You can add a min or max attribute to the input type=date . The date must be in ISO format (yyyy-mm-dd). This is supported in many mobile browsers and current versions of Chrome, although users can manually enter an invalid date without using the datepicker.
I found same question or related question on stackoverflow
Is there any way to change input type=“date” format?
I found one simple solution, You can not give particulate Format but you can customize Like this.
HTML Code:
<body> <input type="date" id="dt" onchange="mydate1();" hidden/> <input type="text" id="ndt" onclick="mydate();" hidden /> <input type="button" Value="Date" onclick="mydate();" /> </body>
CSS Code:
#dt{text-indent: -500px;height:25px; width:200px;}
Javascript Code :
function mydate() { //alert(""); document.getElementById("dt").hidden=false; document.getElementById("ndt").hidden=true; } function mydate1() { d=new Date(document.getElementById("dt").value); dt=d.getDate(); mn=d.getMonth(); mn++; yy=d.getFullYear(); document.getElementById("ndt").value=dt+"/"+mn+"/"+yy document.getElementById("ndt").hidden=false; document.getElementById("dt").hidden=true; }
Output:
If you're using jQuery, here's a nice simple method
$("#dateField").val(new Date().toISOString().substring(0, 10));
Or there's the old traditional way:
document.getElementById("dateField").value = new Date().toISOString().substring(0, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With