How to get Yesterday date without sunday

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

@wsinten

Hi,

    • Use an Assign activity to set the value of the yesterday variable: DateTime.Now.AddDays(-1).
  • 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 the previousBusinessDay variable.
    • For the Sunday case, assign the value yesterday.AddDays(-2) to the previousBusinessDay variable.
    • For the default case (Monday to Friday), assign the value yesterday to the previousBusinessDay variable.
  1. Format the previous business day as yyyyMMdd:
  • Use an Assign activity to format the previousBusinessDay variable as previousBusinessDay.ToString("yyyyMMdd").
  • Assign the formatted value to a variable, for example, previousBusinessDayFormatted.
  1. 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.
  1. 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.

@wsinten

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.