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)