I want to basically translate the code below from Vertica to Hive Syntax:
AND
DATE_TRUNC('WEEK',d.signup_timestamp)
BETWEEN
DATE_TRUNC('WEEK',now()-INTERVAL '8 WEEKS')
AND
DATE_TRUNC('WEEK',now()-INTERVAL '1 WEEK')
I want to basically translate the code below from Vertica to Hive Syntax:
AND
DATE_TRUNC('WEEK',d.signup_timestamp)
BETWEEN
DATE_TRUNC('WEEK',now()-INTERVAL '8 WEEKS')
AND
DATE_TRUNC('WEEK',now()-INTERVAL '1 WEEK')
Date_format function will be a good option here:
WHERE
DATE_FORMAT(d.signup_timestamp, '%V')
BETWEEN
DATE_FORMAT(CURRENT_DATE - INTERVAL 8 WEEK, '%V')
AND
DATE_FORMAT(CURRENT_DATE - INTERVAL 1 WEEK, '%V')
Please note:
(Upper case)%V: Week where Sunday is the first day of the week (01 to 53).
(Lower case)%v: Week where Monday is the first day of the week (01 to 53).
Change it accordingly.
Update:
Current_date is available starting from Hive 1.2.0.
If you use the older version, please use this to replace the current_date.
TO_DATE(FROM_UNIXTIME(UNIX_TIMESTAMP()))