Adding days to a date in Netezza

Russtopher picture Russtopher · Jan 4, 2018 · Viewed 11.8k times · Source

I have a query pulling dates from field [DATE] BETWEEN '10/1/2017' AND '10/31/2017'

I want to add days to the the end date in the between criteria (10/31/2017). It seems impossible. I can add months perfectly using ADD_MONTHS, but there doesn't seem to be a function ADD_DAYS.

Your help is greatly appreciated!

Answer

ScottMcG picture ScottMcG · Jan 4, 2018

add_months deals with the special cases that arise from having variable length months.

For other intervals of time, things are much simpler:

To add 5 days to the current day, use this:

SYSTEM.ADMIN(ADMIN)=> select current_date, current_date + interval '5 days';
    DATE    |      ?COLUMN?       
------------+---------------------
 2017-12-19 | 2017-12-24 00:00:00
(1 row)

T2DB.ADMIN(ADMIN)=> select * from interval_test where col1 between (current_timestamp - interval '2 days') and (current_timestamp + interval '3 days');
    COL1    
------------
 2017-12-19
(1 row)