gpt4 book ai didi

crystal-reports - 更正 Crystal Reports XI 中的 ISO 周编号

转载 作者:行者123 更新时间:2023-12-02 17:46:41 24 4
gpt4 key购买 nike

如何在 Crystal Reports XI 中获取给定日期的 ISO-8601 周数?

最佳答案

Crystal Reports 支持 DatePart 函数,它可以为您提供给定日期的 ISO 周数。

NumberVar week := DatePart("ww", date, crMonday, crFirstFourDays);

但是,在 Crystal Reports XI 中有一个错误会在新年前后给出错误的结果。最好的解决方案可能是创建一个自己的函数 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;

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

// 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 - 更正 Crystal Reports XI 中的 ISO 周编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com