You can use DatePart with "ww" . See IBM Knowledge Center :
DatePart (intervalType, inputDateTime)
...
ww: week of the year (from 1 to 53 with firstDayOfWeek and firstWeekOfYear, which determines the exact days of the first calendar week of the year)
In combination with DatePart ("w", inputDateTime) or DayOfWeek(inputDateTime) receiving the day of the week, you can calculate your first and last day of the current calendar week.
So, for one specific date ( inputDateTime ) this will be your "RangeWeek" formula:
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 provide ToText with the format string you need.
Example:
Input: "August 23, 2017" Output: "Week 34 (August 21 to August 27)"
This simplifies the formula in which 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
Neepsnikeep
source share