How to find the week number, and deduct the dates

and sorry for the “trivial” post, but, I have a lot of difficulty understanding how to use the System.Globalization to manipulate dates.

I have to build a bot, which works only on Mondays, intercepting data from the previous week.

The bot works on SAP, and must set a date range in a query:
from Monday (last week) - to Friday (last week)

Basically, I would need help on this:

  • I would need to know what number it was last week (ex for now: 6_2021)
  • with this data, intercept which date was Monday (01/02/2021)
    and which date was Friday (05/02/2021) of the previous week.

I must use this approach for the eventual recovery of sessions related to the previous weeks.
Basically, I thought that the bot should read the week from a table, and with respect to the week number in the table, calculate the appropriate range date.

I’m really clumsy with handling text strings and System Globalization … sorry sorry sorry… :expressionless:

Hi, @AaronMark!

You can try something like this:


Have a look here:

Maybe you will combine it with this:

cultureinfo.GetCultureInfo.Calendar.GetWeekOfYear(Today, CalendarWeekRule.FirstFullWeek, DayofWeek.Monday).ToString

I am very weak with the use of texts and date conversions.
Unfortunately I cannot find the solution despite the suggestions.

This string is in error, but I recognize which element is to be corrected

Hi ppr
thanks for your reply…
Unfortunately I was unable to use your information, although I think quite valuable.
I’m sorry. As already mentioned,
with strings and dates are very weak.


In my flow, I should read the week number in a table.
and from that, derive the Monday and Friday dates of the previous week.

Right now, my flow does the opposite.

From today’s date, calculate the previous Monday and Friday, and get the week number.

What I need is to start from the week number: 7_2021
and through this, obtain Monday and Friday of the previous week.

Maybe I already have the elements to do this, but I don’t know how to combine them correctly.

Thank you so much peter could you please explain little bit of your use function

1-New DateTime(Year,1,1)
2-offsetFriday=Enumerable.Range(0,7).Where(Function (i) FirstDayDate.AddDays(i).DayOfWeek = DayOfWeek.Friday).First
3offsetWeek=1 - CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(FirstDayDate.AddDays(offsetFriday),CalendarWeekRule.FirstDay, DayOfWeek.Monday)

4WeekDate=FirstDayDate.AddDays(offsetFriday + ((Week + offsetWeek)*7))

Review my screen shot carefully and compare it to your code. You have some extra text that is causing the error.

have a look on following starter help:
GetPreviousWeekMoFr_byWeekNo-Year.xaml (8.1 KB)

for a fast testing, do following:

  • enter in the input dialog week and year in this format: WeekNo_YYYY (1_2021)
  • check the log message:

for reformating the date you can use the toString method, e.g.

Hello PPR.
Sorry for the delay in answering, I only found time now.
Your solution is perfect.
Now I can read from DB the “week + _ + year”, to which I assign the variable “strInput”.
now I just have to convert the dates to the format and that’s it.
Thank you! Very useful.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.