react-flatpickr icon indicating copy to clipboard operation
react-flatpickr copied to clipboard

Convert a selected date range in Flatpickr

Open MateusJSouza opened this issue 2 years ago • 0 comments

Is there any way to convert the date selected by Flatpickr itself? For example:

I select the date in the range of September 5, 2022 to September 12, 2022.

I can get my date through onChange:

onChange={([start, end]) => {
if (start && end) {
    setStartDate(start.toLocaleDateString('pt-BR', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
    }))
    setFinalDate(end.toLocaleDateString('pt-BR', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
    }))
}

After that, my date comes like this: Start date: 09/12/2022 End date: 09/05/2022

Anyway, what I would like to do is convert this received date into something like this: 2022-09-12 and 2022-09-05. Is there a way to do this using Flatpickr?

I tried to use parseDate as it is in the documentation, but I couldn't and I don't know if it would work for my context.

MateusJSouza avatar Sep 19 '22 22:09 MateusJSouza