Santoshadithya
Santoshadithya

Reputation: 13

Need help in Hive on date functions

I am doing functionality testing(need to write hive code while referring Scala code) in my project. I am having an issue with my date functions in my code. In Scala we have casted our date data type into string as changed its structure into ‘YYYYMM’, MY value inside my date column is like 201706(YYYYMM), which is not accepted in Hive (read that it accepts only YYYY-MM-DD).

My question is

1) How to change the YYYYMM to YYYY-MM-DD? I have tried casting to date and also UNIX_TIMESTAMP neither of them are working query is getting failed at the end.

2) We are also using filter.to_date (colm1,”YYYYMM”).between(add_months(to_date((colm2),”YYYYMM”),-27), add_months(to_date((colm2),”YYYYMM”),-2))) in our Scala code , How can I change that to HIVE? Unable to get any ideas

Thanks In advance…..

Regards,

M Sontosh Aditya

Upvotes: 0

Views: 83

Answers (1)

theMerakist
theMerakist

Reputation: 279

use

unix_timestamp(DATE_COLUMN, string pattern)

Further understanding please refer DateFuncitos

Upvotes: 1

Related Questions