DB2 SQL last period (month, quarter, year) last month end of month, last quarter end, last year (often used in statistics) SELECTcurrent timestamp-day (current date) days, -- last month end of month, can know the New Year/* to_date ('1970-02-23 ', 'yyyy-mm-dd')-day (current date) days, -- last month, can know the New year www.2cto.com */case when TO_CHAR ('2017-06-22 ', 'q') = '1' THEN to_char (year ('2017-12-01')-1) | '-12' when TO_CHAR ('2017-06-22', 'q') = '2' THEN to_char (year ('2017-06-22 ')) | '-3' when TO_CHAR ('2017-01-01', 'q') = '3' THEN to_char (year ('2017-12-01 ')) | '-6' when TO_CHAR ('2017-01-01', 'q') = '4' THEN to_char (year ('2017-12-01 ')) | '-9' end as tt, -- the previous quarter month can know the current date of the New Year-(month (current date)-1) month-day (current date) day -- from sysibm at the end of last year. sysdummy1;