date("CalMonth")
date(
string(
string(component("Date",1))
+
case(
string(
component("Date",2)),'1','01','2','01','3','01','4','04','5','04','6','04','7','07','8','07','9','07','10','10','11','10' ,'12','10'
)))
adddays(date(
string(
if("QuarterInt" = 4,string(component("Date",1) +1), string(component("Date",1)))
+
case(
string(
component("Date",2)),'1','04','2','04','3','04','4','07','5','07','6','07','7','10','8','10','9','10','10','01','11','01' ,'12','01'
) ) ),-1)
select
to_date(
to_char(
to_char(Year(Current_date))
||
case when substring(Quarter(Current_date),6) = ('Q1') then '01'
when substring(Quarter(Current_date),6) = ('Q2') then '04'
when substring(Quarter(Current_date),6) = ('Q3') then '07'
when substring(Quarter(Current_date),6) = ('Q4') then '11' end
) )
from dummy
select
add_days(to_date(
case when substring(quarter(current_date),6) = 'Q4' then to_char(Year(Current_date) +1)
else to_char(Year(Current_date)) end
||
case when to_char(month(Current_date)) in ('1','2','3') then '04'
when to_char(month(Current_date)) in ('4','5','6') then '07'
when to_char(month(Current_date)) in ('7','8','9') then '10'
when to_char(month(Current_date)) in ('10','11','12') then '01' end
),-1)
from dummy
select
CASE WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q1')
THEN ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),-3)
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q2')
THEN TO_DATE(YEAR(CURRENT_DATE), 'YYYY')
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q3')
THEN ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),3)
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q4')
THEN ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),6)
end
from dummy
select
CASE WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q1')
THEN ADD_DAYS(TO_DATE(YEAR(CURRENT_DATE)),-1)
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q2')
THEN ADD_DAYS(ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),3),-1)
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q3')
THEN ADD_DAYS(ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),6),-1)
WHEN (SUBSTRING (QUARTER (TO_DATE(CURRENT_DATE, 'YYYY-MM-DD'), 1),6,2) = 'Q4')
THEN ADD_DAYS(ADD_MONTHS(TO_DATE(YEAR(CURRENT_DATE)),9),-1)
End
from dummy
Same can also be achived through below query -
select ADD_DAYS(
to_date(
to_char(
to_char(Year(Current_date))
||
case when substring(Quarter(Current_date),6) = ('Q1') then '01'
when substring(Quarter(Current_date),6) = ('Q2') then '04'
when substring(Quarter(Current_date),6) = ('Q3') then '07'
when substring(Quarter(Current_date),6) = ('Q4') then '11' end
) ) ,-1)
from dummy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
7 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |