116
79

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.

Carbonで日付を比較する

Last updated at Posted at 2016-06-29

日付比較を表にまとめました
どの関数がどの不等号に対応しているかが、パッとわからず毎回チェックするので表を作りました

全般的な使い方は
本家 : http://carbon.nesbot.com/docs/ (英語)
Qiita : http://qiita.com/yudsuzuk/items/ff894bd0b76d4657741d (日本語)
この辺りで

前提

$old = new Carbon('2016-06-01');
$latest = new Carbon('2016-07-01');
$middle = new Carbon('2016-06-15');

結果

意味 code 不等号 結果
等しい $old->eq($latest) $old == $latest false
より大きい $old->gt($latest) $old > $latest false
以上 $old->gte($latest) $old >= $latest false
未満 $old->lt($latest) $old < $latest true
以下 $old->lte($latest) $old <= $latest true
間にあるか $middle->between($old, $latest) $old <= $middle <= $latest true

覚え方

$old->gt($latest):  関数使うオブジェクト greater than 引数のオブジェクト
$old->lte($latest): 関数使うオブジェクト less than equal 引数のオブジェクト
116
79
1

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
116
79

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?