I want to mark as true if date was within last 12 months

Viewed 47

This is what I have done; I am not sure if this is valid and will bring in the outcome that I want

case when lost_renewal_start_date between getdate() and dateadd(day, -365, getdate())
     then true
     else false 
end as churned_within_last_12_months
1 Answers

Try the following:

select *,
       case when 
             lost_renewal_start_date > (current_date - interval '1 year')::date 
             and lost_renewal_start_date <= current_date 
             then true 
             else false
        end as churned_within_last_12_months
from test

See a demo on Postgres from here.

Related