I am reading a date from a locator through cypress the actual date is 11/04/2023
cy.get("#eff-date").invoke('text').then(()=>{
const edate = dayjs(text.split(':')[1].format('DD-MMM-YYYY'))
})
What it is returning
04-Nov-2023
But it should be 11-Apr-2023
2
Answers
You’re attempting to parse a non-ISO 8601 date string. According to the dayjs docs:
The following should work.
More information on using the String + Format (and customParseFormat) here
A better library is date-fns. It will tell you in the test when you get the format wrong.