Use a date and convert it to a week number

Hi,

I am currently working on a project that sends an e-mail to a stakeholder. In this e-mail i want to add an attachment. The name of the attachment has a week number but i am using an assign week number -1, because he needs to add the attachment of the week before. But the problem i have is with a new year uipath make of week 1, week 0. But i want that the robot use week 52 instead of week 0. Now i already tested the follow thing:

  1. Assign for current date
  2. Assign for add days(-1) because he needs to go back 1 week
  3. Make from the date an week number. (dont know how to make this)

I can make the first 2 steps, but the last step is to difficult. Can somebody help me? or do u have an another solution?
I hope u understand my question!
Thanks

Hi,
Could this be the solution for you?

week_of_year = (Date.Today.DayOfYear / 7)

image

Hi @peterlimonade,

This should work for you: (I am here assuming your first week day is a Monday)

DatePart(DateInterval.WeekOfYear, Date.Today.AddDays(-1), FirstDayOfWeek.Monday,FirstWeekOfYear.System)

image

This returns the week number.

1 Like

Thank you for your reaction, your solution does what i want, but when it is 1 january he count this as week 1, But officially is this week 53 and week 1 begins at 4 january.

It might be because we use FirstWeekOfYear.System

You could try this?
FirstWeekOfyear.Jan1 and others. Since I do not know your entire date data I cannot recreate that issue.

Reference: DateAndTime.DatePart Method (Microsoft.VisualBasic) | Microsoft Docs

2 Likes

Thanks, u answered my question! Right now i am using FirstWeekOfYear.FirstFullWeek with this code uipath starts with the first week on 4 january. Thank you for your help!

1 Like

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