Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get last sunday of march and october month using postgre sql?

How to get last sunday of march and october month using postgre sql?

I am looking to fetch last Sunday of march and October every year.

select current_date – extract(dow from current_date)::integer;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This gives me the last sunday

>Solution :

Here is a list of last March and October sundays from year 2000 till 2100. Take the first day of the next month (April, November) for the year, truncate it to the beginning of the week and subtract one day. Do this for every year.

with t(y) as (select generate_series(0, 100, 1))
select
  date_trunc('week', '2000-04-01'::date + interval '1 year' * y)::date - 1 ls_march,
  date_trunc('week', '2000-11-01'::date + interval '1 year' * y)::date - 1 ls_october
from t;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading