extract week number from date postgres

To get the year and the week in a single character value, use to_char()

select to_char(current_date, 'IYYY-IW');

IW returns the year and the week number as defined in the ISO standard and IYYY returns the corresponding year (which might be the previous year).

If you need the year and the week number as numbers, use extract

select extract('isoyear' from current_date) as year, 
       extract('week' from current_date) as week;

Leave a Comment