Belal
Belal

Reputation: 11

How to convert day of the year into a date in hive

Environment: Hive query

How can I convert yyyyddd (ddd=day of the year) with hive query into yyyy-mm-dd ?

Regards,

Upvotes: 0

Views: 1042

Answers (2)

Shalaj
Shalaj

Reputation: 591

you can convert it like below

hive> select from_unixtime(unix_timestamp('2017032','yyyyddd'),'yyyy-MM-dd');

OK
2017-02-01

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269873

You should be able to do this with string manipulation functions. I don't have Hive on hand, but something like this:

date_add(concat(substr(yyyyddd, 1, 4), '-01-01'),
         cast(substr(yyyyddd, 5, 3) as int) - 1
        )

Upvotes: 0

Related Questions