How to get next 12 months, input may be like SEP-2022
Loading
How to get next 12 months, input may be like SEP-2022
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Sep 27, 2022, 2:15 AM EDT
select to_char(generate_series,'MON-YYYY') as next_12_months from generate_series(DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 MONTH', DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '12 MONTH','1 MONTH');Output: next_12_months ---------------- OCT-2022 NOV-2022 DEC-2022 JAN-2023 FEB-2023 MAR-2023 APR-2023 MAY-2023 JUN-2023 JUL-2023 AUG-2023 SEP-2023Uday DodiyaRank #239 · 10.3K reputationPosted Sep 27, 2022, 3:43 AM EDT
From Current Month To 12 Month
SELECT to_char(generate_series(CURRENT_DATE ::timestamp, CURRENT_DATE ::timestamp + interval '12 months', '1 month'), 'Mon-YYYY') AS "Mon-YYYY"Output
Mon-YYYY ---------- Sep-2022 Oct-2022 Nov-2022 Dec-2022 Jan-2023 Feb-2023 Mar-2023 Apr-2023 May-2023 Jun-2023 Jul-2023 Aug-2023 Sep-2023From Jan - 2022 to Dec - 2022
SELECT to_char(generate_series('01-01-2022' ::timestamp, '12-01-2022' , '1 month'), 'Mon-YYYY') AS "Mon-YYYY"Output
Mon-YYYY ---------- Jan-2022 Feb-2022 Mar-2022 Apr-2022 May-2022 Jun-2022 Jul-2022 Aug-2022 Sep-2022 Oct-2022 Nov-2022 Dec-2022Amit MohantyRank #112 · 20K reputationPosted Sep 27, 2022, 12:32 AM EDT
Try this
SELECT to_char(generate_series('2022-01-01'::timestamp, '2022-12-01', '1 month'), 'Mon-YYYY') AS "Mon-YYYY"