Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


velenovs
2012-09-26T14:16:31Z
Hi! I'm looking to create a variable - I can use the "Add number of days" variable to add or subtract days, and I can use the "Last Workday" variable, but I want to combine these two variables somehow and be able to find the date of 2 or 3 workdays back. 😕
Sponsor
Forum information
Support
2012-10-05T07:07:19Z
Not possible right now. I am moving this topic to Feature requests.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
ErikC
2012-10-05T09:52:29Z
Hi velenovs,

What you can do now is using a .NET task with this method:


public static string AddWorkday(int NumberOfDays, string Format)
{
    DateTime ReturnDate = DateTime.Now;            

    if (NumberOfDays > 0)
    {
        while (NumberOfDays > 0)
        {
            switch (ReturnDate.DayOfWeek)
            {
                case DayOfWeek.Friday:
                    ReturnDate = ReturnDate.AddDays(3);
                    break;
                case DayOfWeek.Saturday:
                    ReturnDate = ReturnDate.AddDays(2);
                    break;
                default:
                    ReturnDate = ReturnDate.AddDays(1);
                    break;
            }
            NumberOfDays--;
        }
    }
    else if (NumberOfDays < 0)
    {
		while (NumberOfDays < 0)
        {
			switch (ReturnDate.DayOfWeek)
			{
				case DayOfWeek.Monday:
					ReturnDate = ReturnDate.AddDays(-3);
					break;
				case DayOfWeek.Sunday:
					ReturnDate = ReturnDate.AddDays(-2);
					break;
				default:
					ReturnDate = ReturnDate.AddDays(-1);
					break;
			}
			NumberOfDays++;
		}
    }
	
    return ReturnDate.ToString(Format);
}


Use a Format like yyyyMMdd and the NumberOfDays can be positive or negative number.

Regards,
Erik
Uses Visualcron since 2006.
Scroll to Top