Re: OT weekdates in MSSQL [Re: just to laugh]
Jim H <[email protected]> Sat, 29 Aug 2020 16:15:26 +0000
| Newsgroups | comp.databases.mysql |
|---|---|
| Organization | Forte - www.forteinc.com |
| Message-ID | <[email protected]> |
On Sat, 29 Aug 2020 10:07:45 +0100, in <[email protected]>, Chris Elvidge <[email protected]> wrote: >On 29/08/2020 08:05 am, Luuk wrote: >> On 28-8-2020 16:38, Ammammata wrote: >>> tried this with MS SQL >>> >>> select DATEPART(wk, '20210101') >>> select DATEPART(wk, '20210102') >>> select DATEPART(wk, '20210103') >>> select DATEPART(wk, '20210104') >>> select DATEPART(wk, '20210105') >>> select DATEPART(wk, '20210106') >>> >>> result >>> >>> 1 >>> 1 >>> 2 >>> 2 >>> 2 >>> 2 >>> >>> https://en.wikipedia.org/wiki/ISO_8601#Week_dates >>> >>> >> >> select DATEPART(isowk, '20210101') >> select DATEPART(isowk, '20210102') >> select DATEPART(isowk, '20210103') >> select DATEPART(isowk, '20210104') >> select DATEPART(isowk, '20210105') >> select DATEPART(isowk, '20210106') >> >> result >> >> 53 >> 53 >> 53 >> 1 >> 1 >> 1 >> >> https://docs.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-ver15 >> >> > >IIRC iso weeks start on Monday, ordinary weeks start on Sunday. >Look at the linux 'date' command, specifically %V (%G) and %U >That may suggest why 20210101 is isoweek 53. As I (think I) recall... you can get the ISO week by counting Thursdays in the year to date. -- Jim H