-2

The following logic in SQL Server needs to be converted appropriately to PostgreSQL syntax. Please helpm me convert this over to the correct syntax so I can use it in PostgreSQL database:

  convert(DATE, dateadd(m, -17, convert(DATE, getdate())))
an1234
  • 165
  • 1
  • 12
  • @JeffModen: look at the tooltip for the downvote button "*does not show any research effort*" would be a pretty good fit. –  May 29 '20 at 21:01

2 Answers2

0

Click: demo:db<>fiddle

This subtracts 17 months from your date.

SELECT
    current_date + interval '-17 months'
S-Man
  • 22,521
  • 7
  • 40
  • 63
  • this currently throws an error but if I run just the select with what you just provided it is fine – an1234 May 29 '20 at 20:18
  • SELECT aa4.calendar FROM ods.dim_day as cc LEFT JOIN edw.dim_day as aa4 ON cc.day_of_first_month = aa4.date_id WHERE cc.calendar = (SELECT NOW() + interval '-17 months') – an1234 May 29 '20 at 20:19
  • @an1234 If that worked, please don't forget to accept (to show, that the question has been resolved) and upvote any helpful answer (to honor the work of the repliers). – S-Man Nov 17 '20 at 14:15
0

The equivalent is:

current_date - interval '17 month'

It is curious that the SQL Server code converts to date twice.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786