Impressive! I will do some testing and let you know how it works.
Many thanks!



Bex wrote:ZvezdanD,
I get some strange results with your formula:
Dim i As Integer, dt As Date
dt = DateSerial(2003, 12, 21)
Debug.Print "Date - FDOW: Sun - FDOW: Mon"
For i = 1 To 21
Debug.Print dt & " - " & Format(dt, "ww", 1) & " - " & Format(dt, "ww", 2)
dt = DateAdd("d", 1, dt)
Next
Bex wrote:But I think I'll go with ISO standard and make all the weeks starts on Mondays.
Date - Jet - SQLite Date - Jet - SQLite
2000-01-01 - 1 - 0 2000-12-01 - 49 - 48
2001-01-01 - 1 - 1 2001-12-01 - 48 - 47
2002-01-01 - 1 - 0 2002-12-01 - 48 - 48
2003-01-01 - 1 - 0 2003-12-01 - 49 - 48
2004-01-01 - 1 - 0 2004-12-01 - 49 - 48
2005-01-01 - 1 - 0 2005-12-01 - 49 - 48
2006-01-01 - 1 - 0 2006-12-01 - 49 - 48
2007-01-01 - 1 - 1 2007-12-01 - 48 - 48
2008-01-01 - 1 - 0 2008-12-01 - 49 - 48
2009-01-01 - 1 - 0 2009-12-01 - 49 - 48
2010-01-01 - 1 - 0 2010-12-01 - 49 - 48
2011-01-01 - 1 - 0 2011-12-01 - 49 - 48
2012-01-01 - 1 - 0 2012-12-01 - 49 - 48
2013-01-01 - 1 - 0 2013-12-01 - 48 - 47
2014-01-01 - 1 - 0 2014-12-01 - 49 - 48
2015-01-01 - 1 - 0 2015-12-01 - 49 - 48
2016-01-01 - 1 - 0 2016-12-01 - 49 - 48
2017-01-01 - 1 - 0 2017-12-01 - 49 - 48
2018-01-01 - 1 - 1 2018-12-01 - 48 - 48
2019-01-01 - 1 - 0 2019-12-01 - 48 - 47
2020-01-01 - 1 - 0 2020-12-01 - 49 - 48
cast(strftime('%W', Date) as integer) +
case when firstdayofweek = 1
then
case when cast(strftime('%w', Date, 'start of year') as integer) = 1
then
0
else
1
end
else
case when cast(strftime('%w', Date, 'start of year') as integer) > 1
and (firstdayofweek > cast(strftime('%w', Date, 'start of year') as integer)
or firstdayofweek = 0)
then
case when cast(strftime('%w', Date) as integer) = 0
or cast(strftime('%w', Date) as integer) >= firstdayofweek
and firstdayofweek > cast(strftime('%w', Date, 'start of year') as integer)
then
2
else
1
end
else
case when cast(strftime('%w', Date) as integer) = 0
or cast(strftime('%w', Date) as integer) >= firstdayofweek
and firstdayofweek > 0
then
1
else
0
end
end
endBex wrote:But I think I'll go with ISO standard and make all the weeks starts on Mondays. It might disappoint some US users and others who consider Sunday (or any other day) to be the first day of week.

Function IsoYearWeekSQL(date)
IsoYearWeekSQL = _
"case "&_
" when strftime('%w', "&date&", 'start of year') in ('1','2','3','4') then "&_
" case when strftime('%w', "&date&", '+1 year', 'start of year','-1 day') in ('1','2','3') "&_
" and (((cast(strftime('%j', "&date&") as intiger) + cast(strftime('%w', "&date&", 'start of year') as intiger) - 1-1)/7)+1) = 53 "&_
" then strftime('%Y w ', "&date&",'+1 year')||'01' "&_
" else strftime('%Y w ', "&date&")||substr('0'||(((cast(strftime('%j', "&date&") as intiger) + cast(strftime('%w',"&date&",'start of year') as intiger)-1-1)/7)+1),-2,2) end "&_
" when strftime('%w', "&date&", 'start of year') in ('5','6') then "&_
" case "&_
" when cast(strftime('%w', "&date&", 'start of year') as intiger) + cast(strftime('%j', "&date&") as intiger) <=8 then "&_
" case when strftime('%Y', "&date&", '-1 year') in ('1998','2004','2009','2015') then strftime('%Y w ', "&date&", '-1 year')||'53' "&_
" else strftime('%Y w ', "&date&", '-1 year')||'52' end "&_
" else "&_
" strftime('%Y w ', "&date&")||substr('0'||(((cast(strftime('%j', "&date&") as intiger) + cast(strftime('%w', "&date&", 'start of year') as intiger) - 8-1)/7)+1),-2,2) "&_
" end "&_
" when strftime('%w', "&date&", 'start of year') = '0' then "&_
" case "&_
" when strftime('%j', "&date&") = '001' then "&_
" case when strftime('%Y', "&date&", '-1 year') in ('1998','2004','2009','2015') then strftime('%Y w ', "&date&", '-1 year')||'53' "&_
" else strftime('%Y w ', "&date&", '-1 year')||'52' end "&_
" else "&_
" strftime('%Y w ', "&date&")||substr('0'||(((cast(strftime('%j', "&date&") as intiger) -1-1)/7)+1),-2,2) "&_
" end "&_
"end "
End FunctionTeknojnky wrote:Bex wrote:But I think I'll go with ISO standard and make all the weeks starts on Mondays. It might disappoint some US users and others who consider Sunday (or any other day) to be the first day of week.
hrmm, 98273498372 billion americans can't be wrong!
![]()
![]()
The great advantage of having International
Standards is that they make it easy for the
American people to differ from everybody else.

Bex wrote:I have actually written a piece of code which gives the ISO year & week.
cast(strftime('%W', Date) as integer) +
case when cast(strftime('%w', Date, 'start of year') as integer) = 1
then
0
else
1
endUsers browsing this forum: Bing [Bot], psbot [Picsearch] and 14 guests