0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

うるう年の計算

Posted at

考え方

年齢は、生まれた日を初日として計算します。例えば、4月1日が誕生日の人の場合、4月1日が初日となり、翌年の3月31日の24時になった瞬間に年齢が加算されます。そうすると、2月29日生まれの人は理論上、2月29日は2月28日の24時に加算されます。つまりうるう年以外は3月1日に思えますが、、、

免許証の有効期限で定義されていました。

うるう年の誕生日では2月29日となりますが、それ以外の誕生日は2月28日となります。うるう年の場合は2月29日まで有効であり、それ以外は2月28日まで有効となります。

この理論に基づいて、Tableau Prepではどう計算されるのか検証してみました。

準備したデータ

1992年2月29日の誕生日の人が、基準日において、年齢が何歳になるか計算してみます。

image.png

計算式

基準日の年の誕生日を計算して、基準日前ならば「西暦年の差」、基準日後ならば西暦年の差マイナス1」で年齢を求めます。

IF DATEADD('year', DATEDIFF('year', [誕生日], [基準日]), [誕生日]) > [基準日] 
	THEN DATEDIFF('year', [誕生日], [基準日]) -1
ELSE
	DATEDIFF('year', [誕生日], [基準日])
 END

結論

うるう年以外の基準日では2月28日を誕生日、うるう年は基準日が2月29日を誕生日となっており、免許証の有効期限とあっていることがわかりました。

image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?