Spanish date received from API

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.

Thanks!!

What is the format you want to use for your date? Is that on the client side or in a server action?

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

image

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)

<input type="text" class="form-control" id="inp_Fecha" name="Fecha" dmx-bind:value="queryObtenerComprobanteIA.data.FormRecognizer.data.analyzeResult.documentResults[0].fields.fecha.text.toDate()" is="dmx-date-picker" format="DD/MM/YYYY">
<input id="text1" name="text1" type="text" class="form-control" dmx-bind:value="queryObtenerComprobanteIA.data.FormRecognizer.data.analyzeResult.documentResults[0].fields.fecha.text">

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.

It’s the date obtained from an OCR and it’s retrieving the same as it’s displayed

You can do this on the server side to reformat the string and convert to date:

{{(mydate.split('/')[2]+'-'+mydate.split('/')[1]+'-'+mydate.split('/')[0]).formatDate('yyyy-MM-dd hh:mm:ss')}}

where mydate is the date value you are working with.

1 Like