score:0

Accepted answer

date-fns takes date as an argument. first you should convert your string date value to a valid date instance. date could take several types of value, including iso 8601 date standard, which means you could pass 2022-02-22 string value to date constructor and it will be valid.

if your string format is not going to change your could do this:

const datestr = '20220211';
const year = datestr.slice(0,4);
const month = datestr.slice(4,6);
const day = datestr.slice(6,8);
const date = new date(`${year}-${month}-${day}`);

and then use date in date-fns


Related Query

More Query from same tag