tiempo

isSameMonth

Check if two datetimes are in the same calendar month

Returns true if both datetimes are in the same calendar month.

Signature

function isSameMonth(
  date1: Temporal.Instant | Temporal.ZonedDateTime,
  date2: Temporal.Instant | Temporal.ZonedDateTime
): boolean

Parameters

ParameterTypeDescription
date1Temporal.Instant | Temporal.ZonedDateTimeThe first datetime
date2Temporal.Instant | Temporal.ZonedDateTimeThe second datetime

Returns

true if both datetimes are in the same calendar month, false otherwise.

Examples

import { isSameMonth } from '@gobrand/tiempo';

const jan1 = Temporal.ZonedDateTime.from('2025-01-01T00:00:00Z[UTC]');
const jan31 = Temporal.ZonedDateTime.from('2025-01-31T23:59:59Z[UTC]');
const feb1 = Temporal.ZonedDateTime.from('2025-02-01T00:00:00Z[UTC]');

isSameMonth(jan1, jan31); // true
isSameMonth(jan31, feb1); // false

On this page