计算年数的一个函数

Q:
I've got a datetime column in my database for a person's age. How would
I be able to calculate the number of years they are from the DB date to
current time?
A:
 
ruby 代码
 
  1. def age  
  2.   ((Time.now - birthday)/(60*60*24)/365.2422).to_i  
  3. end  

你可能感兴趣的:(Ruby)