Equivalent of iso_week in SQL workbench

Skip to first unread message

trobolo dinni

Sep 13, 2022, 11:28:44 AM9/13/22
to SQL Workbench/J - DBMS independent SQL tool
Dear Thomas,

I am trying to calculate the week number of a specific date from the start of the year. However, using for example  "select  date_part('week', date) as start_week"  yields wrong results because in most cases the first week of the year is split between the target year and the previous one.
In other SQL versions the keyword "iso_week" can be used to circumvent this issue. Is there any simple way to do the same in SQL workbench?


Thomas Kellerer

Sep 14, 2022, 3:57:21 AM9/14/22
to sql-wo...@googlegroups.com

this has nothing to do with SQL Workbench/J.

Whether or not `date_part()` with a ISO week is supported or not, totally depends on the database product being used.
SQL Workbench only sends your query to the database server - there is nothing SQL Workbench/J can do about, if your database doesn't support the features you need.

If you are using Postgres (which the use of date_part() seems to suggest), then date_part('week') will return the ISO week.
Typically this only makes sense if you combine it with the ISO year.

Reply all
Reply to author
0 new messages