extract week number from date postgres
问题 I would like to extract the week number as: 2015-52 from a date formatted as: 2015-12-27 How can I perform this in postgres? my weeks are calculated from monday to sunday. 回答1: 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