I'm using date-fns I would like to convert new Date(2020,1,10) to 'Thursday'. I'm trying to use
dateFns.format(new Date(2020,1,10),'dddd')
but it returns 0001?
Thanks in advance
I'm using date-fns I would like to convert new Date(2020,1,10) to 'Thursday'. I'm trying to use
dateFns.format(new Date(2020,1,10),'dddd')
but it returns 0001?
Thanks in advance
Use this for full Day name:
import {format} from 'date-fns';
format(new Date(2020,1,10), 'EEEE')
This also works:
format(new Date(2020,1,10), 'iiii')
"dddd"
only works in older versions of date-fns (< 2.0.0) for getting the day of the week. In newer versions, "dddd"
is replaced with "EEEE"
.
For me using date ("2022-10-29")
and format(new Date(date), 'EEEE')
showed wrong weekday Friday instead of Saturday (I am Central Time), from my understanding I need to provide time to get correct weekday.
for some reason this using different "Month Day, Year" format this worked: {format(parseISO(date), "MMMM d, yyyy")}
=> October 29, 2022
Since I had time in different variable, I have combined, date and time {format(new Date(date + "T" + time + "Z"), "EEEE")}
this seem to work, shows correct weekday: Saturday
© 2022 - 2024 — McMap. All rights reserved.
EEEE
is the correct answer, but I made the same mistake because of their documentation date-fns.org/v1.30.1/docs/format – Tattered