LoginSignup
0
0

More than 1 year has passed since last update.

ActiveSupport::Duration で経過した月数を計算する

Posted at
[1] pry(main)> now = Time.current
=> Thu, 26 Jan 2023 19:07:20 JST +09:00

[2] pry(main)> past = Time.current.ago(6.months)
=> Tue, 26 Jul 2022 19:07:22 JST +09:00

[3] pry(main)> ActiveSupport::Duration.build(now - past).parts
=> {:months=>6, :days=>1, :hours=>9, :minutes=>5, :seconds=>22.157833217}

[4] pry(main)> ActiveSupport::Duration.build(now - past).parts.dig(:months)
=> 6
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