在Crystal Reports XI中更正ISO周编号 [英] Correct ISO week numbering in Crystal Reports XI
本文介绍了在Crystal Reports XI中更正ISO周编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取Crystal Reports XI中指定日期的ISO-8601周编号?
How can I get the ISO-8601 week number of a given date in Crystal Reports XI?
推荐答案
Crystal Reports支持 DatePart
- 可以给出给定日期的ISO周编号的函数。
Crystal Reports supports the DatePart
-function which can give you the ISO week number of a given date.
NumberVar week := DatePart("ww", date, crMonday, crFirstFourDays);
但是,在Crystal Reports XI中有一个错误,最好的解决方案是创建一个自己的函数getISOWeekNumber:
However, in Crystal Reports XI there is a bug that gives erronous results round new year. The best solution is probably to create an own function 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;
要获取特定日期的周年,您可以使用以下函数:
To get the "week-year" of a specific date, you could then use the following function:
// 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);
这篇关于在Crystal Reports XI中更正ISO周编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文