LoginSignup
0
0

More than 1 year has passed since last update.

#ruby で Date = 日付を足し算、引き算して差分の日数を得る

Last updated at Posted at 2019-07-05

(Date.new(2019, 10, 01) - Date.new(2019, 07, 01)).to_i
# => 92

くわしく


Date.new(2019, 10, 01) - Date.new(2019, 07, 01)
# => (92/1)
# 何これ

(Date.new(2019, 10, 01) - Date.new(2019, 07, 01)).class
# => Rational
# Rational というクラスのインスタンスらしい

(Date.new(2019, 10, 01) - Date.new(2019, 07, 01)).to_i
# => 92
# to_i すると差分の日付が得られる

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
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
0
0