This solution has to work for every day of the week, E.G.
if Today is 21/08/023, Monday, what is the date on Friday this week?
If Today is 26/08/2023,Saturday, what is the date on Friday next week? 01/09/2023
we assume the following
Monday, Tuesday, Wednesday, Thursday - Friday same week
Friday - same day, as it is Friday
Saturday, Sunday - Friday next week
This can be modelled by an offset Array
myDate.AddDays({5,4,3,2,1,0,6}(myDate.DayOfWeek))
Hey @Rowley101,
You can try
if(Today.DayOfWeek> System.DayOfWeek.Friday, Today.AddDays((Today.DayOfWeek - 5)*-1).Date.AddDays(7), Today.AddDays((Today.DayOfWeek - 5)*-1).Date)
will MyDate by “22/08/2023” in date format?
do you write the whole statement, other than the if, into an If activity?
if so im getting an error
myDate has to be Variable of DateTime
We can parse:
and later we can reformat by:
myDate.AddDays({5,4,3,2,1,0,6}(myDate.DayOfWeek)).toString("dd/MM/yyyy")
Hi @Rowley101
Try this:
if Today is 21/08/023, Monday, what is the date on Friday this week?
Assign activity:
Dim today As DateTime = New DateTime(2023, 8, 21) ' Use your desired date here
Dim daysUntilFriday As Integer = (DayOfWeek.Friday + 7 - today.DayOfWeek) Mod 7
Dim fridayThisWeek As DateTime = today.AddDays(daysUntilFriday)
Log Message activity:
Output: "Date for Friday this week: " + fridayThisWeek.ToString("dd/MM/yyyy")
If Today is 26/08/2023,Saturday, what is the date on Friday next week? 01/09/2023
Assign activity:
Dim today As DateTime = New DateTime(2023, 8, 26) ' Use your desired date here
Dim daysUntilFriday As Integer = (DayOfWeek.Friday + 7 - today.DayOfWeek) Mod 7
Dim nextWeekFriday As DateTime = today.AddDays(6)
Log Message activity:
Output: "Date for Friday next week: " + nextWeekFriday.ToString("dd/MM/yyyy")
Hope it helps!!
If you want to keep it as a string of format dd/MM/yyyy then use,
if(Today.DayOfWeek> System.DayOfWeek.Friday,
Today.AddDays((Today.DayOfWeek - 5)*-1).Date.AddDays(7).ToString("dd/MM/yyyy"),
Today.AddDays((Today.DayOfWeek - 5)*-1).Date.ToString("dd/MM/yyyy"))