daysInMonth

A utility function to calculate the number of days in the month of a given date.
> daysInMonth(date: Date = new Date()): number
Parameters
  • date (optional): The date to determine the number of days in its month. Defaults to the current date (new Date()).
  • Returns: The number of days in the month of the provided date.

Example

import { daysInMonth } from "@explita/daily-toolset";

// Get the number of days in the current month
const currentMonthDays = daysInMonth();
console.log(currentMonthDays); // e.g., 30 (for November 2024)

// Get the number of days in February 2024 (leap year)
const februaryDays = daysInMonth(new Date("2024-02-15"));
console.log(februaryDays); // 29

// Get the number of days in a custom date's month
const customDate = new Date("2023-06-12");
const juneDays = daysInMonth(customDate);
console.log(juneDays); // 30

Use Cases

  • Determining the number of days for billing cycles or schedules.
  • Validating date ranges within a specific month.
  • General utility for calendar-based applications.