# Checking if two dates match with MomentJS

> How to check if two dates are the same with the JavaScript libray MomentJS

Source: https://curiouslychase.com/engineering/checking-if-two-dates-match-with-momentjs/

With [MomentJS](https://curiouslychase.com/engineering/momentjs/) ([JavaScript](https://curiouslychase.com/posts/javascript/)), you can check if two times are the same with the `isSame` method.

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

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

Then use the `isSame` method: 

```js
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)](https://curiouslychase.com/posts/dataview-obsidian/) queries for [Obsidian](https://curiouslychase.com/tools/obsidian/).

[reference](https://momentjscom.readthedocs.io/en/latest/moment/05-query/02-is-same/)

#javascript #programming #obsidian/programming

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