简体   繁体   中英

How to get last Sunday including today in PostgreSQL?

Is it possible to get last Sunday in PostgreSQL including today's day?

For example if today is Sunday expression returns today's date. If today is other day it returns nearest last Sunday.

Try this:

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

Sunday is 0 in Postgres, so this date adjustment is exactly what you describe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM