Convert Week & Weekday to Date

Hello,

I can find a lot on how to convert a date to week, but I cannot find anything online on how to convert a week and weekday to a date.

For example:
Week 36 2019
Monday
6:00 AM

Needs to be converted to 02 September 2019 06:00 AM

Week 36 2019
Tuesday
9:00 AM

Needs to be converted to 03 September 2019 09:00 AM

I have tried with datetime and with datetime.parse, but I am not getting any wiser.

If anyone has an idea I would be very happy.

Good morning SJonsson,

Do any of the solutions in this post help?

Hello @chenderson,

I had a look at that one as well, but since I need it for a lot of different weekdays it was very unreliable.
Especially since it can be any given week of the year and combined with a weekday.

Are you able to add an additional input to the code stage for WeekDay?

In my workflow you mean? Yes I can add more, but from the input I cannot add anything, so need to process it in UiPath if possible. Otherwise I will solve it in Excel, even if that is less elegant.

Hope this helps

This is the first assignment statement, which uses the Calendar to add weeks to the first day of the year. Note that we add one less than the week supplied because Jan 1st is already in week one.

myCal.AddWeeks(Convert.ToDateTime(“1/1/” & Now.Year.ToString), inWeek - 1)

The second assignment statement shifts the day to Sunday (Day 0), adds the day value to get to the right day of the week (after converting the day name to a number), and then adds the number of hours. The hours that you want will need to be in military format though (6:00 for 6AM, 18:00 for 6PM, etc).

outDate.AddDays(-outDate.DayOfWeek + Convert.ToInt32(DayOfWeek.Parse(GetType(DayOfWeek), inDay))).Add(Timespan.Parse(inHour))

1 Like

Thank you! I will have a look at it and see if I am able to solve my problem with it.

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