Date Truncation in Apache Hive

This function returns the truncated date to the unit defined by the format. This will aim to return the first day of the specified month on the first day of the specified year.
Supported formats: MONTH/MON/MM, YEAR/YYYY/YYY.

Syntax: TRUNC(string date, string format)

Examples: 
SELECT TRUNC(‘2020-04-26 13:04:05.000’, “MM”);
This returns 2020-04-01
You can use “MM” or “MONTH” or “MON”

SELECT TRUNC(‘2020-04-26 13:04:05.000’, “YY”);
This returns 2020-01-01
You can use “YY” or “YEAR” or “YYYY”

Trunc_in_Hive
Hope you find this article helpful.

Please click on the follow button to receive updates on latest posts.

4 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s