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

前端 未结 13 2200
被撕碎了的回忆
被撕碎了的回忆 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 17:11

    To calculate number of Years and Months between two dates, I used this function

      def calculate_year_month(from_date, to_date)
        num_days = (from_date - to_date).to_i
        num_months = (num_days / 30) 
        num_years = (num_months / 12) 
        num_months = (num_months % 12) 
        return num_years.to_s + " year(s) and " + num_months.to_s + " month(s)" 
      end 
    
    0 讨论(0)
提交回复
热议问题