Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

ADD MONTHS in Greenplum

In Greenplum, you can use the DATEADD() function to add or subtract months from a date. Here's how you can use it:

SELECT DATEADD(MONTH, 3, DATE '2022-01-15') AS new_date;

This query will add 3 months to the date '2022-01-15', resulting in the date '2022-04-15'.

Similarly, you can subtract months by using a negative value:

SELECT DATEADD(MONTH, -2, DATE '2022-01-15') AS new_date;

This query will subtract 2 months from the date '2022-01-15', resulting in the date '2021-11-15'.

So, in Greenplum, you use the DATEADD() function to add or subtract months from a date by providing the appropriate positive or negative number of months.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.