ColRow
ColRow

Reputation: 79

Subtracting months from date using Redshift

I know I can use dateadd to add an interval to a date, what about subtracting, would I just use a negative number? Here is an example:

select "date_table"."id_date" >= date_trunc('month', dateadd(month,-18, current_date)) 
from "date_table"

Upvotes: 1

Views: 6765

Answers (1)

GMB
GMB

Reputation: 222682

what about subtracting, would I just use a negative number?

Yes. This works:

dateadd(month, -18, current_date)

You can also use add-months():

add_months(current_date, -18)

Or interval litterals:

current_date - interval '18 months'
current_date - interval '1 year, 6 months'

Upvotes: 4

Related Questions