Check if a date occurs in the current year

Compare the UTC year of a date-time with the current one.

JavaScript Version 1.0.0 · MIT · .md

check-if-a-date-occurs-in-the-current-year.js
function isCurrentYear({ dateTime, now }) { return new Date(dateTime).getUTCFullYear() === new Date(now).getUTCFullYear(); }

Input & expected output

Input

{
  "dateTime": "2026-01-15T00:00:00Z",
  "now": "2026-10-28T12:00:00Z"
}

Expected output

true

The edge case

Input

{
  "dateTime": "2025-12-31T23:00:00-03:00",
  "now": "2026-10-28T12:00:00Z"
}

Expected output

true

Know the limits

  • The year is the UTC year: New Year’s Eve at 23:00 in São Paulo is already 2026 in UTC, as the edge case shows.
  • now is an input so the result is testable.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Check if a date occurs in the current year from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Takes the current time as an explicit input so the result is reproducible. Original MDX retained as inert source evidence.

Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/check-if-a-date-occurs-in-the-current-year.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.