overflow overflow - 6 months ago 13
SQL Question

Current week number for current month

I used following query to get current week

select extract(week from current_timestamp)
and it is showing
34
thats fine.

But how do i get the current week number of the current month.

Answer

You can find the week number that starts this month with:

extract(week from date_trunc('month', current_date))

So this month's week number would be:

extract(week from current_date) - 
    extract(week from date_trunc('month', current_date)) + 1
Comments