Chase AdamsChase Adams
AboutContentPromptsPrototypesNewsletter

Checking if two dates match with MomentJS

Essays and updates on product, engineering, and AI by Chase Adams.

1 minute read

Post Details

Published
Nov 13, 2022
Category
Engineering
Share
ChatGPT

Latest Posts

A 2x2 Framework for Navigating AI Disruption

A 2x2 Framework for Navigating AI Disruption

Not all change requires the same response. A new framework for diagnosing which kind of disruption you're facing—and choosing the right strategy.

With MomentJS (JavaScript), you can check if two times are the same with the isSame method.

First, instantiate moment with the date you want to check:

const someDate = "2021-07-14";
const currMoment = moment(someDate);

Then use the isSame method:

const someDate = "2021-07-14";
const currMoment = moment(someDate);

const anotherDate = "2021-07-13";

const isSameDay = currMoment.isSame(anotherDate, "day") // false
const isSameMonth = currMoment.isSame(anotherDate, "month") // true

I use this heavily in my Dataview (Obsidian) queries for Obsidian.

reference

#javascript #programming #obsidian/programming

Created:: 2021-07-14 12:42:36

AboutAI Workflow SpecContentStacksNewsletterPromptsRSS