This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing few facts on DATE ADD operations of PostgreSQL.
In the PostgreSQL, there is no DATEADD() function for performing date operations.
We can perform DATE add or subtract using arithmetic operator.
But with this option, I observed something which we should know before doing DATE ADD or DATE SUBTRACT.
Observation 1:
First, the partial result is 2017-02-28, then add five months to it.
So 2017-07-28 is this correct result, or are you looking for 2017-07-31.
1 2 3 4 |
SELECT ('2017-01-31'::date + '1 month'::interval) + '5 month'::interval; ?column? --------------------- 2017-07-28 00:00:00 |
Observation 2:
1 2 3 4 |
SELECT '2017-01-31'::date + ('1 month'::interval + '5 month'::interval); ?column? --------------------- 2017-07-31 00:00:00 |
Observation 3:
1 2 3 4 |
SELECT ('2017-01-31'::date + '5 month'::interval) + '1 month'::interval; ?column? --------------------- 2014-07-30 00:00:00 |
Check above all observations and decide which result is correct for you.
Leave a Reply