我正在使用HiveQL,我只需要使用“出生日期”列来计算年龄,但是问题是GetDate
不起作用,但是Current_Date()
起作用。我正在尝试的示例是
datediff(yy,Dateofbirthcol,current_date()) As Age
。
DOB列看起来像1988-12-14
。
尝试以下选项之一。
floor(datediff(to_date(from_unixtime(unix_timestamp())), Dateofbirthcol) / 365.25)
datediff(now(), Dateofbirthcol) / 365.25
请勿使用unix_timestamp(),因为它是non-deterministic。使用current_date:
datediff(current_date, Dateofbirthcol) / 365.25