How to calculate how many years passed since a given date in Ruby?

前端 未结 13 2243
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 16:33

This question was here for other languages, so let here be one for Ruby.

How do I calculate number of complete years that have passed from a given date? As you prob

13条回答
  •  我在风中等你
    2020-12-09 16:53

    you can use the ruby gem adroit-age

    It works for leap years also..

    age = AdroitAge.find_age("23/01/1990")
    

    Update

    require 'adroit-age'
    
    dob =  Date.new(1990,1,23)
    or
    dob = "23/01/1990".to_date
    
    age = dob.find_age
    #=> 23
    

提交回复
热议问题