Date Range Based on Day of Week

I’m trying to automate a report. When the report runs on Thursday, it needs to run the report with the dates of Friday-Sunday. When it runs on Monday is needs to run with the dates of Tuesday-Friday. Each day is it’s own report.

I know I can split them into individual jobs to accomplish it. I was wonder if it’s possible/sensible to accomplish both requirements in a single workflow.

You can do that,

You will get the day using Now.DayOfWeek.ToString

It will return the day and using if condition you can check that as
if(Now.DayOfWeek.ToString = “Thursday”) or “Monday”

You want to run the dates of previous week?

Fine
its very simple buddy @rridlen
–if the process is run on Thursday…or any day let it be
inside the process at the very beginning use a variable inside a assign activity like this
date_system = Datetime.Now.DayOfWeek
the output would be date_system = Thursday (this is not going to be used, and we can pass this a input to log message activity or write line activity which can be used for debugging)
where date_system is a variable of type string
–coming to the point
now inside the workflow we need to pass the date value to its variable
lets say we are using a variable named in_date_1 and in_date_2, a string variable along the process then the value of in_date_1 and in_date_2 should be mentioned as
in_date_1 = Datetime.Now.AddDays(1).DayOfWeek.ToString //output is Friday
in_date_2 = Datetime.Now.AddDays(3).DayOfWeek.ToString //output is Sunday

Thats all buddy you can use this in_date_1 and in_date_2 along the process
Hope this would help you
kindly try this and let know for any queries or clarification
Cheers @rridlen

Current week

did that work buddy
Cheers @rridlen

Hi @rridlen

I have a good component that you can use to get your dates generated.

https://go.uipath.com/component/data-manipulations#

In this pack, you’ll find an activity called “Custom Date Series”. Provide the date pattern you need and it will give you the required dates as needed without much of a hassle :slight_smile:

This is an example pattern for your scenario where you need dates for friday to sunday “1111000”. If you give this pattern to the activity, it will generate the dates from friday to sunday. Here 1 represents a holiday and 0 represents a working day where you need to get the dates. The pattern starts from Monday and ends with Sunday. So first digit represents Monday…

Change the pattern as you need for every scenario and it will get it done for you :slight_smile:

Hope this helps to make it easier

2 Likes

Yes @Palaniyappan, I was able to implement that.

@Lahiru.Fernando I’ll test that custom activity out as well and see how it goes.

Thank you everyone.

2 Likes

Fantastic
Cheers @rridlen

1 Like

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