I want to find out the previous month's last day, but I want it for last year, in Teradata SQL.
Examples:
If current date is '2022-02-02', then the output I require is '2021-01-31'
If current date is '2022-07-25', then the output I require is '2021-06-30'
CodePudding user response:
I think this should do it:
SELECT ADD_MONTHS(CURRENT_DATE – EXTRACT(DAY FROM CURRENT_DATE) 1, -12) - 1
-- get the first day of current month
-- subtract 12 months
-- subtract 1 day
CodePudding user response:
Substract 13 months from today and then find the last day of this month:
last_day(add_months(current_date, -13)
