age - 脚本和图表函数
age 函数用于返回某人在 date_of_birth 出生的 timestamp (完整年份)时的年龄。
语法:
age( timestamp,
date_of_birth )
可以是表达式。
返回数据类型: 数字
参数:
参数
timestamp
时间戳或用于对时间戳求值的表达式都可用于计算完成的年份数量。
date_of_birth
正在计算其年龄的人的出生日期。 可以是表达式。
示例和结果:
以下示例使用日期格式 DD/MM/YYYY 。日期格式已经在数据加载脚本顶部的 SET DateFormat 语句中指定。可以根据要求更改示例中的格式。
脚本示例
age('25/01/2014', '29/10/2012')
返回 1 。
age('29/10/2014', '29/10/2012')
返回 2 。
示例:
将示例脚本添加到应用程序并运行。要查看结果,将结果列中列出的字段添加到应用程序中的工作表。
Employees:
LOAD * INLINE [
Member|DateOfBirth
John|28/03/1989
Linda|10/12/1990
Steve|5/2/1992
Birg|31/3/1993
Raj|19/5/1994
Prita|15/9/1994
Su|11/12/1994
Goran|2/3/1995
Sunny|14/5/1996
Ajoa|13/6/1996
Daphne|7/7/1998
Biffy|4/8/2000
] (delimiter is |);
AgeTable:
Load *,
age('20/08/2015', DateOfBirth) As Age
Resident Employees;
Drop table Employees;
结果列表显示了为表格中的每条记录返回的 age 值。
结果表
Member
DateOfBirth
Age
John
28/03/1989
26
Linda
10/12/1990
24
Steve
5/2/1992
23
Birg
31/3/1993
22
Raj
19/5/1994
21
Prita
15/9/1994
20
Su
11/12/1994
20
Goran
2/3/1995
20
Sunny
14/5/1996
19
Ajoa
13/6/1996
19
Daphne
7/7/1998
17
Biffy
4/8/2000
15