You can use DatePart
with "ww"
, too. See IBM Knowledge Center:
DatePart (intervalType, inputDateTime)
...
ww: Week of year (1 to 53 with firstDayOfWeek and firstWeekOfYear determining the exact days of the first calendar week of the year)
Combined with DatePart ("w", inputDateTime)
or DayOfWeek(inputDateTime)
getting the day of week, you can calculate your first and last day of the current calendar week.
So for one specific date (inputDateTime
), this would be your formula "RangeWeek":
Function (DateTimeVar inputDateTime)
NumberVar cw := DatePart("ww", inputDateTime);
DateTimeVar first := DateAdd("d", 1 - DayOfWeek(inputDateTime, crMonday), inputDateTime);
DateTimeVar last := DateAdd("d", 7 - DayOfWeek(inputDateTime, crMonday), inputDateTime);
"Week " + ToText(cw) + " (" + ToText(first) + " to " + ToText(last) + ")"
You need to give ToText the format strings you want, of course.
Example:
Input: "August 23, 2017"
Output: "Week 34 (August 21 to August 27)"
That makes things easier in the formula where you get the date range.
DateTimeVar from := ...;
DateTimeVar to := ...;
NumberVar cw;
NumberVar count := 0;
StringVar output := "";
for cw := DatePart("ww", from) to DatePart("ww", to) do
(
output := output + chr(13) + RangeWeek(DateAdd("d", 7*count, from));
count := count + 1;
);
output