Date Manipulation - trunc

#1

Let us understand how to use trunc on dates or timestamps and get beginning date of the period.

  • We can use MM to get beginning date of the month.
  • YY can be used to get begining date of the year.
  • We can apply trunc either on date or timestamp, however we cannot apply it other than month or year (such an hour or day).
DESCRIBE FUNCTION trunc;

SELECT trunc(current_date, 'MM');
SELECT trunc('2019-01-23', 'MM');
SELECT trunc(current_date, 'YY');
SELECT trunc(current_timestamp, 'HH'); // will not work

Practice hive on state of the art Big Data cluster - https://labs.itversity.com
You can sign up for our courses on Udemy using $10 coupons - Udemy Coupons - Big Data Courses


0 Likes