Recently, I had a need to calculate the week. I looked at the ready-made code on the Internet, but it was not suitable, so I had to do it myself.
By default, the first Monday of the year starts the first week.
'Calculate the start date of the first week of a certain year
function firstday(inputyear)
for i=cdate(inputyear&"-1-1") to cdate(inputyear&"-1-7")
if weekday(i)=2 then
firstday=i
exit for
end if
next
end function
'Calculate the input date is a function of the week of the year
FunctionCalcWeekNo(InputDate)
toyear=year(inputdate)
fday=firstday(toyear)
if datediff("d",fday,inputdate)<0 then
fday=firstday(toyear-1)
end if
'calcweekno=fday
daynum=datediff("d",fday,inputdate)
calcweekno=int(daynum/7)+1
end function
'Calculate the first day of the week based on the week number and year
function getfst(inputyear,weekno)
fday=firstday(inputyear)
getfst=dateadd("d",(weekno-1)*7,fday)
end function