Check previous day date (without weekends)

Hi All,

My case
Reports are generated and save in dedicated folder.
Each day between Monday and Friday reports is generated and saved, only weekends are excluded (which means if there is a holiday during a week, raport is also generated)
Now I need to check today if I have a report from previous working day (exclude only Saturday and Sunday)
I need this because Im comparing two reports

Thank you

Hi @niteckam

Check this

Thanks
Ashwin S

@niteckam

You want previous day(Exclude only Saturday and Sunday ) or Previous created file?

Hi @amaresan

It will be good to have previous day in format dd.mm.yyyy
Then I can use it as part of path to find the right report.

Thank you

        DateTime today = DateTime.Now;
        DateTime prevWorkday = today.AddDays(-1);
        while (prevWorkday.ToString("dddd") == "Saturday" || prevWorkday.ToString("dddd") == "Sunday")
        {
            prevWorkday = prevWorkday.AddDays(-1);
        }
        string prevWorkdayString = prevWorkday.ToString("dd.MM.yyyy");

This will give you your most recent workday, this does not take into account federal holidays or anything of that sort. For this you could use something like the Nager package to give you holiday information based on country code and add some additional logic to account for it.

NOTE: The prevWorkdayString = prevWorkday.ToString("dd.MM.yyyy"); is where you can actually format the date however you’d like for whatever format the files you’re searching for has it in. Just change the "dd.MM.yyyy" portion, but keep in mind "mm" is minutes and "MM" is months.

All you need to do now it port this code into UiPath using their elements or if you run C# you may be able to use invoke code, not sure though, I’ve never really played around with it, but the logic is laid out.

3 Likes

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