0

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.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Nina
  • 1
  • 1
  • 2

2 Answers2

2

Try one of the following option.

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

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

zealous
  • 7,336
  • 4
  • 16
  • 36
0

Do not use unix_timestamp() because it is non-deterministic. Use current_date:

 datediff(current_date, Dateofbirthcol) / 365.25
leftjoin
  • 36,950
  • 8
  • 57
  • 116
  • 3
    Please don't post only code as an answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes. – today Apr 28 '20 at 23:18
  • Thank you every one for all your help and I am sorry I will not be doing that next time – Nina Apr 29 '20 at 03:30