There are multiple ways to do that. Here are couple of examples:
Exploring the examples above
On a side note, you can convert datetime to date format using toDateString.
Let’s look at this code and the result:
I used the querySelector to get the element, doesn’t really matter matter what method you use to get the element .
The toISOString method gives us nice string that we can use to extract the date from.
So, as we saw in the example 1, all we need to do is get the first 10 characters from the ISO date string using substr method.
On a side note, there is a difference between substr and substring methods.
In the second example, I used valueAsDate method that returns or sets the value of the element as a date.
If conversion is not possible then it will set the value as null.
current date default input today