[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
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme