Q:
I've got a datetime column in my database for a person's age. How wouldA:
I be able to calculate the number of years they are from the DB date to
current time?
ruby 代码
- def age
- ((Time.now - birthday)/(60*60*24)/365.2422).to_i
- end
本文介绍了一种使用Ruby编程语言来计算从数据库中获取的出生日期到当前日期之间的年数的方法。通过简单的数学运算,我们可以精确地计算出一个人的年龄。
590

被折叠的 条评论
为什么被折叠?



