Let’s say you’d like to have a header showing a week exactly N weeks ago from the current date. You can do it using our repeater widget and the algorithm I explain below.
I want to see in my header dates from a week that was two weeks ago, starting from Sunday. Today is Friday, Feb.2, 2024, so the week I’d like to see is the one that begins on Sunday, Jan 14th. It should look the following way:
Widget setup: A rectangle widget is placed inside the repeater.
Variables:
Current date: to store the value of the current date;
StartDate: to store the value of the start date depending on the current day of the week.
Index: to store the value of the [[Item.Index]].
Counter: to increment, it’s set to 0 at the beginning.
The algorithm: I assign the value [[Now]]] to the variable “CurrentDate” on the Page Loaded event.
Then, on the “Item Loaded” event, I check what weekday is now by setting a condition that checks if the “CurrentDate” contains the parts of the weekdays (“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”) and I also set that the value of the Index variable is less than 8 (since I need to show data only for seven days).
After this, I set the value of the variable “StartDate” to Sunday, which was two weeks ago, by using the [[AddDays()]] function. Since today is Friday, the Sunday I need happened 19 days ago, and then I add the value of the “Counter” to increment the days throughout the week.
Then, I set the text on the rectangle to the format I want: “Day of the week, Month/Day” by using [[Slice()]] and [[GetMonth()]] functions.
So far, all this happens only for the first rectangle in the row, but I want these actions to be populated for the entire week. For this, I set the value of the variable [[Index]] to [[Item.Index+1]], and I also increment the variable “Counter”. As a result, we get a loop that sets the desired dates for the entire week. We’ll need six more conditions for each weekday respectively.
Here is how it looks like and a copy of my file TwoWeeksAgo_R.rp (53.3 KB).
I hope this can help you save some time!