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 days from a given date, in this post.
DAYS_ADD and DAYS_SUB are the functions that adds and subtracts a specified number of days from a TIMESTAMP value. These functions deal with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.
Syntax:
DAYS_ADD(TIMESTAMP startdate, INT days),
DAYS_ADD(TIMESTAMP startdate, BIGINT days)
DAYS_SUB(TIMESTAMP startdate, INT days),
DAYS_SUB(TIMESTAMP startdate, BIGINT days)
Examples:
SELECT NOW() AS CurrentDate, DAYS_ADD(NOW(), 30) DateAfter30Days;
….—…………CurrentDate…………….|………..–.DateAfter30Days–………..
2021-10-30 09:15:41.895351000 | 2021-11-29 09:15:41.895351000
SELECT NOW() AS CurrentDate, DAYS_SUB(NOW(), 30) DateBefore30Days;
….—…………CurrentDate…………….|………..–.DateBefore30Days–………..
2021-10-30 09:15:41.895351000 | 2021-09-30 09:15:41.895351000
I hope you found this post to be informative.
Please join our mailing list to receive more interesting information.