sql - Get the timestamp of a day of the week -


I am trying to find a certain daytime timestamp with postgrsQL. For example, I can use () to get a current time, but I want to return the same type of data, such as, most recently on Monday or Sunday.

I am looking for this because I have a query that gets data now a few months ago and I do not want to include the current week. As an example, what does it do now:

  creation_date & gt; Now () - Interval '2 months'   

I thought it could achieve my goals:

  Between now () - interval' 4 months' and now () - INTERVAL '1 week'   

But it only decreases the query by 7 days which I do not want. In fact, I want to:

  between now () - interval '4 months' and ????   

Where the question marks are the timestamps for the most recent Sunday, at least I believe it will work.

date_trunc ('week', current_date) - interval '1' day

date_trunc ('week', current_date) will return the date at the beginning of the week

The week starts on Monday in postgres. This is the reason that you have to reduce the time of the second day to get results for Sunday.

Comments