DEV Community

Lumin
Lumin

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 (1)

Collapse
 
codetobuild profile image
codetobuild

This post is like a flash of insight! It's short, clear, and gets right to the point. No extra stuff to bog you down. Time to call it a day and head home!