从DOB计算年龄

问题描述 投票:0回答:2

我正在使用HiveQL,我只需要使用“出生日期”列来计算年龄,但是问题是GetDate不起作用,但是Current_Date()起作用。我正在尝试的示例是

datediff(yy,Dateofbirthcol,current_date()) As Age

DOB列看起来像1988-12-14

sql hadoop hive hiveql
2个回答
1
投票

尝试以下选项之一。

  1. floor(datediff(to_date(from_unixtime(unix_timestamp())), Dateofbirthcol) / 365.25)

  2. datediff(now(), Dateofbirthcol) / 365.25


0
投票

请勿使用unix_timestamp(),因为它是non-deterministic。使用current_date:

 datediff(current_date, Dateofbirthcol) / 365.25
© www.soinside.com 2019 - 2024. All rights reserved.