如何获得7天或每周取决于Crystal Report公式字段中的日期范围?
Example:
Date Range from March 01, 2014 to March 31, 2014
Output:
Week 1 (March 01 to March 07)
Week 2 (March 08 to March 14)
Week 3 (March 15 to March 21)
Week 4 (March 22 to March 28)
Week 5 (March 29 to March 31)
最佳答案
自定义函数RangeWeekSplitter
在一年内有效。 Crystal 语法。
Function (dateTimeVar dFrom, dateTimeVar dTo)
// First day of the year
local dateTimeVar dBegCurrYear:= Date (Year(dFrom), 1, 1);
// Day of year (1 to 365 or 366 in a leap year)
local numberVar nFrom:= DatePart ("y", dFrom);
local numberVar nTo:= DatePart ("y", dTo);
local numberVar i;
local numberVar iTo;
local numberVar nDaysInWeek:= 7; // number of days in the week
local numberVar nWeek:= 0; // counter weeks
local stringVar sResult:= ""; // output string
for i:= nFrom to nTo step nDaysInWeek do
(
nWeek:= nWeek+1;
iTo:= i+(nDaysInWeek-1);
if(i+nDaysInWeek > nTo)
then iTo:= nTo;
// generate output string
sResult:= sResult + chr(13)+
"Week " + CStr(nWeek) + " (" +
CStr(DateAdd ("y", i-1, dBegCurrYear), "MMMM d") +
" to " +
CStr(DateAdd ("y", iTo-1, dBegCurrYear), "MMMM d") +
")";
);
sResult;
用法示例:
// Date range
local dateTimeVar dFrom:= Date (2016, 1, 14);
local dateTimeVar dTo:= Date (2016, 3, 4);
RangeWeekSplitter (dFrom, dTo);
关于crystal-reports - 如何获取Crystal Report中日期范围的每周或7天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23212094/