Hi,
I’d like to ask. How to get yesterday’s file (filename format yyyyMMdd) but only Monday to Friday (Saturday and Sunday holidays). When I use “DateTime.Now.AddDays(-1).ToString((“yyyyMMdd”)" in assign activity, When Monday will still search for data on Sunday. how do you do it on Monday, the robot automatically searches for Saturday? thank you
Hi,
-
- Use an Assign activity to set the value of the
yesterday
variable:DateTime.Now.AddDays(-1)
.
- Use an Assign activity to set the value of the
- Use a Switch activity to check the day of the week of
yesterday
.- Configure the Switch activity to have cases for Saturday and Sunday.
- For the Saturday case, assign the value
yesterday.AddDays(-1)
to thepreviousBusinessDay
variable. - For the Sunday case, assign the value
yesterday.AddDays(-2)
to thepreviousBusinessDay
variable. - For the default case (Monday to Friday), assign the value
yesterday
to thepreviousBusinessDay
variable.
- Format the previous business day as yyyyMMdd:
- Use an Assign activity to format the
previousBusinessDay
variable aspreviousBusinessDay.ToString("yyyyMMdd")
. - Assign the formatted value to a variable, for example,
previousBusinessDayFormatted
.
- Query the files:
- Use a Directory.GetFiles activity to retrieve the list of files in the target directory.
- Set the search pattern to
previousBusinessDayFormatted + "*"
to match files with the desired filename format. - This will give you an array of file paths that match the previous business day’s date.
- Process the files as needed:
- Use a For Each activity to iterate through the array of file paths obtained in the previous step.
- Within the loop, perform the necessary operations on each file.
You can use this
If(Now.DayOfWeek = DayOfWeek.Monday, Now.AddDays(-3), If(Now.DayOfWeek = DayOfWeek.Sunday, Now.AddDays(-2), Now.AddDays(-1))).ToString("yyyyMMdd")
Cheers
1 Like
use now.Dayofweek to get the day in integer format so 1 = monday, 2 = tuesday etc.
Then use an if statement for if now.dayofweek = 1 then the file name will be filename + date.today.adddays(-3).tostring(“yyyyMMdd”)
Hi @wsinten
Hope this workflow might help you solve your query:
Sequence7.xaml (12.1 KB)
Hope it helps!!
Regards,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.