Reputation: 15
I need to get only Thursday dates when I pass any date in that week using built-in date functions in postgres. How?
Upvotes: 0
Views: 513
Reputation: 3262
Do you want to get the date of the same weeks thursday returned? That would be:
SELECT date_trunc('week','2020-02-15'::date) + interval '4 days'
Upvotes: 2
Reputation: 168
You could use the EXTRACT( dow FROM date) function to get what day of the week a given date is and test if the result is a 4, which should be a thursday.
SELECT
days :: DATE,
to_char(days,'Day'),
EXTRACT(dow FROM days) as day_of_week
FROM generate_series ('2019-02-01', '2019-02-28', '1 day' :: interval ) AS days
https://www.postgresql.org/docs/9.0/functions-datetime.html
Upvotes: 0