I just want to validate if the string that i received is a valid date using date-fns. I gonna receive a date like this '29/10/1989', BR date. I want to transform it into 29-10-1989 and check if its valid. Anyone can help me with this?
const parsedDate = parseISO('29/10/1989')
this code above doesnt work, i got 'Invalid Date'
Try parse
with locale
options like this:
import { parse, isValid, format } from 'date-fns';
import { enGB } from 'date-fns/locale';
const parsedDate = parse('29/10/1989', 'P', new Date(), { locale: enGB });
const isValidDate = isValid(parsedDate);
const formattedDate = format(parsedDate, 'dd-MM-yyyy');