Get week number in year?

I want to get week number in year.

If I have variable int = 3 ( for use backward date)
today = 28/10/2021
I want to get week by date = 25/10/2021 ----> output = 44

Please guide me about it.

1 Like

CultureInfo.CreateSpecificCulture(“en-US”).Calendar.GetWeekOfYear(New Datetime(2021,10,25), CalendarWeekRule.FirstFullWeek,DayOfWeek.Monday)

ensure

  • System.Globalization is added to the imports
  • set the locals to your present locals

About the week rule enum also have a look here:

And here:

CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(New Datetime(2021,10,25), CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday)

@ppr If I want use variable in date month year.
How to edit code?

we would recommend following:

  • create a variable e.g. checkDate | datatype: DateTime
    Assign acitvity
    LHS: checkDate
    RHS: new DateTime(myYearVar, myMonthVar, myDayVar)

myDayVar similar to the dd from the screenshots

then just use the var within the statement:

CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(checkDate,
CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday)

@ppr I use follow your suggest.
But output is not correct.

output show : 43
But true number week must = 44 as below.

image

have a look on the provided screenshot from above where the calendarWeekRule was modified and showing 44. Same is to check for the dayOfWeek Settings if it has do to be adopted

One additional thing:
we can save a lot of time when prototyping directly on the immediate box. For further debugging options have a look here:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

1 Like

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