QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Get Days in Month

Calculates the number of days in a specific month of a given year.

  • date
  • days-in-month

Install

npx shadcn@latest add https://quicksnip.dev/r/get-days-in-month.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate();

Usage

getDaysInMonth(2024, 1); // Returns: 29 (February in a leap year)
getDaysInMonth(2023, 1); // Returns: 28