Hi everyone. I’m having some trouble while trying to insert to a date input element a date obtained from an API.
My API retrieves the date in the Spanish format: dd/mm/yyyy and when I use .toDate() function it messes up the order between date and month.
How could I change de order of the date received from the API in order to arrange it with the English format? I beleive I need to use .split() and other transformation function but maybe there’s a shorcut.
Is on the client side, but could be on server side too.
The format should be comprehensible enough to be added into a date input object. The dd/mm/yyyy is not correctly inserted inside the input.
Checkout these examples
The first input is a date input which converts the text string .toDate() because I can’t set the date input value with the original text string. The date displayed is incorrect, checkout the code below.
The second input is a text input which gets the original string with the correct date (displayed in dd/mm/yyyy)
Where exactly do you get the date from? This is not a valid date format to work with.
You should always work with dates in format yyyy-MM-dd and only convert the format for the users.