There are plenty of built-in functions available in Apache Impala that helps in analyzing the data and business logic implementations. It relieves a developer’s worries and eliminates the necessity for user-defined functions. Built-in functions aid analysts in the process of analyzing, cleansing, transforming, and modeling data in order to identify valuable information, draw conclusions, and support decision-making.
This is one of a series of articles describing how to use “date-time” functions. We’ll go through how to add and subtract a certain number of hours from a given date, in this post.
HOURS_ADD and HOURS_SUB are the functions that adds and subtracts a specified number of hours from a TIMESTAMP value. These functions deal with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.
Syntax:
HOURS_ADD(TIMESTAMP startdate, INT days),
HOURS_ADD(TIMESTAMP startdate, BIGINT days)
HOURS_SUB(TIMESTAMP startdate, INT days),
HOURS_SUB(TIMESTAMP startdate, BIGINT days)
Examples:
SELECT NOW() AS CurrentDate, HOURS_ADD(NOW(), 23) DateAfter23Hours;
….—…………CurrentDate…………….|………..–.DateAfter23Hours–………..
2021-11-01 14:27:27.661854000 | 2021-11-02 13:27:27.661854000
SELECT NOW() AS CurrentDate, HOURS_SUB(NOW(), 23) DateBefore23Hours;
….—…………CurrentDate…………….|………..–.DateBefore23Hours–………..
2021-11-01 14:28:32.326555000 | 2021-10-31 15:28:32.326555000
I hope you found this post to be informative.
Please join our mailing list to receive more interesting information.