Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to subtract days or months from datetime using postgresql/netezza

I have this sql query that is working fine but would like to convert it into some kind of postgresql or netezza equivalent query. Here are my queries:

SELECT name, location, Date FROM myTable WHERE [Date] < DateAdd(hh, 48, [shipDate]

and other query

SELECT name, location, Date FROM myTable WHERE [Date] < DateAdd(d, 90, [shipDate]
like image 474
moe Avatar asked Aug 31 '25 18:08

moe


1 Answers

For Netezza the easiest thing to do is use an interval calculation:

SELECT name, location, Date FROM myTable WHERE Date < shipDate + interval '48 hours';
SELECT name, location, Date FROM myTable WHERE Date < shipDate + interval '2 days';
SELECT name, location, Date FROM myTable WHERE Date < shipDate + interval '90 days';

You can also use add_months if you want to do month calculations that are aware of the different length of the months.

SELECT name, location, Date FROM myTable WHERE Date < add_months(shipdate, 3);
like image 158
ScottMcG Avatar answered Sep 02 '25 21:09

ScottMcG