In: Computer Science
Write a query to return the date and day of the week of the first day of the month two years from today.
If today is 10/16/20, then the expect output is 10/01/2022 and the day of the week is thursday.
I am using postgresql.
first of all 10/01/2022 ---> oct /01/2022 is saturday. not thursday.
try the below query
----------------------------------------------
with daynumber as (select date_trunc('month', current_date + interval '2 years')as date,extract(isodow from date_trunc('month', current_date + interval '2 years')) - 0 daynumber ),
week as(select CASE
WHEN daynumber.daynumber =1 THEN 'Monday'
WHEN daynumber.daynumber=2 THEN 'Tuesday'
WHEN daynumber.daynumber=3 THEN 'Wednesday'
WHEN daynumber.daynumber=4 THEN 'Thursday'
WHEN daynumber.daynumber=5 THEN 'Friday'
WHEN daynumber.daynumber=6 THEN 'Saturday'
WHEN daynumber.daynumber=7 THEN 'Sunday'
ELSE 'other'
END from daynumber )
select *from daynumber,week;
-----------------------------------
output