NumberVar yearnumber := DatePart ("yyyy",{table.datetime}, crMonday, crFirstFourDays); // use {table.datetime} here
NumberVar weeknumber := DatePart ("ww",{table.datetime}, crMonday, crFirstFourDays); // use {table.datetime} here
// Date falls in week 53 and weekday of 1 jan next year is smaller than 5 (meaning week 53 has less than 4 days)
// Make it week 1 of the next year
if weeknumber=53 and DayOfWeek (cdate(yearnumber+1,1,1), crMonday) < 5 then
(
weeknumber := 1;
yearnumber := yearnumber+1;
)
// Week is in week 1 or a week higher then 53 (happens with the first days where week 53 of the previous year has 4 days)
// And extra check that indeed the last week of the last year had at least 4 days and that the input date is weekday 5 or larger
else if (weeknumber=1 or weeknumber>53) and DayOfWeek (cdate(yearnumber-1,12,31), crMonday) > 3 and DayOfWeek ({table.datetime}, crMonday) > 4 then // use {table.datetime} here
(
weeknumber := DatePart ("ww",cdate(yearnumber-1,12,31), crMonday, crFirstFourDays);
yearnumber := yearnumber-1;
);
totext (yearnumber,0,'') & '/' & totext (weeknumber,"00");