Issue
I have an API that returns the dates in a string format as shown below. How to set the value of the input type date to this value?
let str = "2020-1-1"
<input type= "date" value = {value} />
Solution
You will have to format the date into YYYY-MM-DD before passing it to the date input.
To do this, you can use:
const str = "29/11/2020";
const [day, month, year] = str.split('/');
const date = `${year}-${month}-${day}`;
<input type="date" value={date} />
Answered By - Mohammad Dohadwala
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.