Reputation: 1
I am using HiveQL and I need to calculate the age just by using the Date of birth column but the issue is GetDate
doesn’t work however Current_Date()
does. The example I am trying is
datediff(yy,Dateofbirthcol,current_date()) As Age
.
The DOB column looks like 1988-12-14
.
Upvotes: 0
Views: 10602
Reputation: 38335
Do not use unix_timestamp() because it is non-deterministic. Use current_date:
datediff(current_date, Dateofbirthcol) / 365.25
Upvotes: 0
Reputation: 7503
Try one of the following option.
floor(datediff(to_date(from_unixtime(unix_timestamp())), Dateofbirthcol) / 365.25)
datediff(now(), Dateofbirthcol) / 365.25
Upvotes: 2