一般的に計算する場合は下記計算式で。
(今日の日付-誕生日)/10000の小数点以下切捨て
PHP
echo (int)((20120423 - 19741029)/10000);
Perl
print int ((20120423 - 19741029)/10000);
Java
System.out.println( (int)((20120423 - 19741029)/10000) );
Perl
#!/usr/bin/perl use strict; my $byear = 1974; my $bmon = 10; my $bday = 29; my ($day, $mon, $year) = (localtime(time))[3-5]; my $now = sprintf( "%04d%02d%02d", $year+1900, $mon+1, $day ); my $birth = sprintf( "%04d%02d%02d", $byear, $bmon, $bday ); my $age = int( ($now - $birth) / 10000 ); print $age, "\n";
コメント