2006-12-25

计算年数的一个函数

关键字: rails
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  

评论
发表评论

您还没有登录,请登录后发表评论

sea gull
搜索本博客
存档
最新评论
评论排行榜