3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Moment.jsで対象の日付が期間内か判定するisBetween()の使い方メモ。

Last updated at Posted at 2020-03-17

タイトルの通りです。

isBetWeen()は対象の日付が期間内かどうかを判定する事ができます。

追記:Moment.jsはレガシープロジェクトになりました

Moment.js for Apps ScriptのおおもとであるJSのMoment.jsは2020年9月をもって新機能などの開発は廃止となりました。 詳しくはこちら
今後新規開発するときはあまりMoment.jsを使わない方がいいかもしれません。

JSとしてはLuxonというのが後継となるそうです。
Luxon for Apps Scriptとかできるといいですね!

使い方


moment('2020-03-03').isBetween('2020-03-01', '2020-03-05', 'day', '(]'); // true

param1: 比較したい期間の初め
param2: 比較したい期間の終わり
param3: どの単位で比較するか
param4: 以上、より大きい、以下、未満の指定

param3はyear, month, day, hour, minuteのどれか、
param4は下記の通り。
'(' : '<'
')' : '>'
'[' : '<='
']' : '>='

重複判定とかに役立てられる。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?