DEV Community

Teerasak Vichadee
Teerasak Vichadee

Posted on

Get first date and last date of months with date-fns

Do not wasted time with native Date, use date-fns and go home!

import { format, lastDayOfMonth } from 'date-fns'

const today = new Date()
const firstDateOfMonth = format(today, 'yyyy-MM-01')
const lastDateOfMonth = format(lastDayOfMonth(today), 'yyyy-MM-dd')
Enter fullscreen mode Exit fullscreen mode

Now go home!

Top comments (0)