Crystal reports 水晶报表席中的ISO周编号 < P> >如何在水晶报表席Xi?< /P> < P>水晶报表中支持给定日期的ISO-8601星期编号支持 DatePart < /C> >函数,该函数可以给出给定日期的ISO周数。< /P> NumberVar week := DatePart("ww", date, crMonday, crFirstFourDays); 然而,在水晶报表席中,有一个错误,它给新年带来了错误的结果。最好的解决方案可能是创建自己的函数getISOWeekNumber: Function (optional DateVar d := CurrentDate) NumberVar week := DatePart("ww", d, crMonday, crFirstFourDays); // Correct for that CR doesn't handle the fact that the last days of a year can belong to week 1 of the next year: if week = 53 and DatePart("ww", cDate(year(d) + 1, 1, 1), crMonday, crFirstFourDays) = 1 then week := 1 // A bug in CR makes DatePart return values like 9363 for days in January that belongs to the last week of the previous year. else if week > 53 then week := DatePart("ww", cDate(year(d) - 1, 12, 31), crMonday, crFirstFourDays); week;

Crystal reports 水晶报表席中的ISO周编号 < P> >如何在水晶报表席Xi?< /P> < P>水晶报表中支持给定日期的ISO-8601星期编号支持 DatePart < /C> >函数,该函数可以给出给定日期的ISO周数。< /P> NumberVar week := DatePart("ww", date, crMonday, crFirstFourDays); 然而,在水晶报表席中,有一个错误,它给新年带来了错误的结果。最好的解决方案可能是创建自己的函数getISOWeekNumber: Function (optional DateVar d := CurrentDate) NumberVar week := DatePart("ww", d, crMonday, crFirstFourDays); // Correct for that CR doesn't handle the fact that the last days of a year can belong to week 1 of the next year: if week = 53 and DatePart("ww", cDate(year(d) + 1, 1, 1), crMonday, crFirstFourDays) = 1 then week := 1 // A bug in CR makes DatePart return values like 9363 for days in January that belongs to the last week of the previous year. else if week > 53 then week := DatePart("ww", cDate(year(d) - 1, 12, 31), crMonday, crFirstFourDays); week;,crystal-reports,iso,crystal-reports-xi,week-number,Crystal Reports,Iso,Crystal Reports Xi,Week Number,要获取特定日期的“周-年”,您可以使用以下功能: // Returns the year to which the ISO week of the specified date belongs. // E.g. 2012-12-31 will return 2013, as that date belongs to week 1 of 2013. Function (optional DateVar d := CurrentDate) NumberVar week := getISOWeekN

要获取特定日期的“周-年”,您可以使用以下功能:

// Returns the year to which the ISO week of the specified date belongs.
// E.g. 2012-12-31 will return 2013, as that date belongs to week 1 of 2013.
Function (optional DateVar d := CurrentDate)

NumberVar week := getISOWeekNumber (d);

if week = 1 and month(d) = 12 then
    year(d) + 1
else if week > 10 and month(d) = 1 then
    year(d) - 1
else
    year(d);

2012年12月31日应该被视为2013年的第一周,这与我的直觉相反,但看起来你是对的。这也是2008年的一个错误。如果你想每周都有7天(这是你一直想要的),那么你必须决定在新的一年中这一周的名称。将其称为“2012-53/2013-01”或许更直观,但可以说并不更好。ISO-8601只是简单地命名了一周中大部分天数所属年份之后的整周。