Home > OS >  How to get year and quarter for sysdate in Oracle Sql
How to get year and quarter for sysdate in Oracle Sql

Time:11-30

I want to get the quarter and year depending on the sysdat in Oracle sql. For example i want expected result value as 2022q3 for current quarter.

I can get the quarter using below query:

select to_char(sysdate, 'Q') as qtr from  dual;

CodePudding user response:

You can achieve this with the format string 'YYYY"Q"Q':

select to_char(sysdate, 'YYYY"Q"Q') as qtr
from dual

A possible way to get previous quarter:

select to_char(sysdate - interval '3' month, 'YYYY"Q"Q') as qtr
from dual
  • Related