How to extract date from timestamp field in hive

Viewed 363

Timestamp column is : 20210817 16:45

I want to extract only date part using Hive query language.

Please help me with this.

1 Answers

Using regexp_replace:

select date(regexp_replace('20210817 16:45', '^(\\d{4})(\\d{2})(\\d{2}).*','$1-$2-$3'))

Result:

2021-08-17

Note: date() function is not necessary here, string in yyyy-MM-dd is fully compatible with Hive date type.

Related