1
2

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 5 years have passed since last update.

生年月日を年齢に変換

Posted at
function birth2Age(birth, base) {
  var timezone;
  if (base == null) base = new Date;
  timezone = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone();
  birth = Utilities.formatDate(birth, timezone, 'yyyyMMdd');
  return parseInt((Utilities.formatDate(base, timezone, 'yyyyMMdd') - birth) / 10000);
}
birth2Age = (birth, base = new Date) ->
  timezone = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone()
  birth = Utilities.formatDate birth, timezone, 'yyyyMMdd'
  parseInt (Utilities.formatDate(base, timezone, 'yyyyMMdd') - birth) / 10000

スプレッドシートの関数としても使える。

=birth2Age(A3)
=birth2Age(A4, B4)
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?