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 years from a given date, in this post.
YEARS_ADD and YEARS_SUB are the functions that adds and subtracts a specified number of years from a TIMESTAMP value. These functions deal with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.
Syntax:
YEARS_ADD(TIMESTAMP startdate, INT days),
YEARS_ADD(TIMESTAMP startdate, BIGINT days)
YEARS_SUB(TIMESTAMP startdate, INT days),
YEARS_SUB(TIMESTAMP startdate, BIGINT days)
Examples:
SELECT NOW() AS CurrentDate, YEARS_ADD(NOW(), 1) DateAfter1Year;
….—…………CurrentDate…………….|………..–.DateAfter1Year–………..
2021-11-01 14:12:35.512112000 | 2022-11-01 14:12:35.512112000
SELECT NOW() AS CurrentDate, YEARS_SUB(NOW(), 1) DateBefore1Year;
….—…………CurrentDate…………….|………..–.DateBefore1Year–………..
2021-11-01 14:13:13.109998000 | 2020-11-01 14:13:13.109998000
I hope you found this post to be informative.
Please join our mailing list to receive more interesting information.
2 comments