Obtain last Friday's date based on today's date

Hello all,

I need to determine a range of dates, in which the From date = last Friday’s date (mm/dd/yyyy) based on today. Any suggestions on how to accomplish this?

Hello rjackson,

Welcome to our Community!

I would use a loop with a counter that goes backwards.

Loop 1:
If Now.AddDays(-1).DayOfTheWeek.ToString = “Friday”

LastFriday = Now.AddDays(-1).ToString(“MM/dd/yyyy”)

Break

Loop 2;

If Now.AddDays(-2).DayOfTheWeek.ToString = “Friday”

LastFriday = Now.AddDays(-2).ToString(“MM/dd/yyyy”)

Loop 3;

If Now.AddDays(-3).DayOfTheWeek.ToString = “Friday”

LastFriday = Now.AddDays(-3).ToString(“MM/dd/yyyy”)

And on an on until you get a Friday.

Was it clear?

DId this help you?

Kind regards,
Daniel

Hi
welcome to uipath community
this is really interesting and i have tried this one time either
so the steps would be like this
–lets take a string variable
str_currentdate = Now.DayofWeek.ToString

–now use a while loop like this
NOT str_currendate.ToString.Equals(“Friday”)
and inside the loop use
–a assign activity like this
str_currentdate = now.AddDays(-1).Dayofweek.ToString
Final_Date = Now.AddDays(-1).ToString
–so next to this while loop use a write liine activity and mention like this
Final_Date.ToString
so the value will be last friday date

Cheers @rjackson

Hi,

The following expression might help you. This needs no loop.

lastFridayDate = Today.AddDays(7*Cint(Today.DayOfWeek<=DayOfWeek.Friday)+(DayOfWeek.Friday-Today.DayOfWeek))

Regards,

5 Likes

Hi

This does not work - as the current date is always used for the loop. My suggestion is:

–lets take a string variable
str_currentdate = Now.DayofWeek.ToString
-also take current date as date in assign
DateTemp = Now

–now use a while loop like this
NOT str_currendate.ToString.Equals(“Friday”)
and inside the loop use
–a assign activity like this
str_currentdate = DateTemp.AddDays(-1).Dayofweek.ToString
Final_Date = DateTemp.AddDays(-1).ToString
–so next to this while loop use a write liine activity and mention like this
Final_Date.ToString
so the value will be last friday date

Let me know if you agree
Regards

Hello,

This solution is giving me an infinite loop. Could you please a xaml file with an example?

Thank you

Hi Yoichi,
read this and found this interesting can you please explain what is the logic behind this.

Thanks in Advance !

Hello All,

I have done this using while loop. Please see below screenshot.