Skip to main content
Home

Utility functions for working with dates

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
a month ago (5.0.0)
function firstDateOfMonth
firstDateOfMonth(date?: Date): Date

Returns the first date of the month for a given date.

Examples

Example 1

import { assert } from '@std/assert'

// Using the current date (default parameter)
const firstDay = firstDateOfMonth();
assert(firstDay.getDate() === 1) // First day of the current month

Example 2

import { assertEquals } from '@std/assert'

// December 2022
assertEquals(
  firstDateOfMonth(new Date('2022-12-15')),
  new Date(2022, 11, 1)
)

Example 3

import { assertEquals } from '@std/assert'

// February (leap year)
assertEquals(
  firstDateOfMonth(new Date('2024-02-29')),
  new Date(2024, 1, 1)
)

Parameters

optional
date: Date = new Date()
  • The date from which to extract the month. Defaults to the current date.

Return Type

The first date of the month.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";
or

Import directly with a jsr specifier

import { firstDateOfMonth } from "jsr:@edouardmisset/date/first-date-of-month.ts";

Add Package

pnpm i jsr:@edouardmisset/date
or (using pnpm 10.8 or older)
pnpm dlx jsr add @edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";

Add Package

yarn add jsr:@edouardmisset/date
or (using Yarn 4.8 or older)
yarn dlx jsr add @edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";

Add Package

vlt install jsr:@edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";

Add Package

npx jsr add @edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";

Add Package

bunx jsr add @edouardmisset/date

Import symbol

import { firstDateOfMonth } from "@edouardmisset/date/first-date-of-month.ts";