Days of the week calculation

I have a variable that stores days of the week, for example Monday, Tuesday, etc. and I want to add x days. How do I do this?
Example:
Variable = Monday
Add 2 days
Result = Wednesday

Hi @Maria_Ines_Almeida,

Here’s how you can solve it:

I put together a workflow for this—adding the screenshot for you to check out. You just enter the starting day and the number of days to add, and it gives you the correct day automatically. For example, if you start with Monday and add 2 days, it’ll give you Wednesday as the result.

Here is the code:

System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames((Array.IndexOf(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames, DayOfWeek) + DaysToAdd) Mod 7)

This way, you don’t have to enter the days manually; it’ll handle it all for you. Let me know if this helps!

Regards,
Furkan

Hello,

Are you using C#? Typically, in C# you would want to store your Date/Time data as a DateTime type. If this is the case, you can invoke the .AddDays(x) method off of your variable which returns a new DateTime where integer x is the amount of days added to the date.

So, if you have a DateTime that is on Monday name myVariable, you could use an Assign activity assigning myVariable.AddDays(2) which will return a new DateTime 2 days in the future.

Hi,

FYI, another approach:

strDay = "Monday"
x =2

Then

CType(((CInt(DayOfWeek.Parse(GetType(DayOfWeek),strDay,True))+x) mod 7),DayOfWeek)

(This returns DayOfWeek type.)

OR

CType(((CInt(DayOfWeek.Parse(GetType(DayOfWeek),strDay,True))+x) mod 7),DayOfWeek).ToString()

(This returns String type)

Regards,

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