LoginSignup
21
10

More than 5 years have passed since last update.

誕生日から年齢を簡単計算

Last updated at Posted at 2016-03-23

美墨なぎさの年齢を求めてみる

birthday = Date.parse('1990-10-10') 
(Date.today.strftime('%Y%m%d').to_i - birthday.strftime('%Y%m%d').to_i) / 10000
#25@2016-03-23 

冷静に考えてみたら当たり前なんだけど、頭いい計算方法だな。
Yearの引き算と、誕生日を越えてなければ1引く処理が一つにまとまってる。

21
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
10