If its Friday or Saturday, Select Monday

I’m trying to find the most efficient way to code this.

    IF Date.Now.DayOfWeek.ToString = "Friday" OR Saturday 

      Then the new date should become the Monday that follows. 

The date needs to be returned as a short date string so that it
can be entered into the date field on the application form that I’m automating.
This is what I was going to do, but I feel like maybe someone has a better way of doing this.

IF  dayofweek = friday

   Date.Add(3 days) 

ELSE IF dayofweek = saturday

   Date.Add(2 days)

Else It's not the weekend yet.


The one you tried is the correct one and easiest way.

1 Like

I just wish it could be a one liner I guess. Lol.

1 Like

Hello @HsDev,
You could use Switch case.


1 Like

Hi @HsDev,

Here I have attached the sample to your situation handle by switch case.

Sample : Heathersmithx.zip (11.4 KB)


1 Like

hmmm fine
may be like this lol
say if we have a variable of type string named in_day with value as “Friday” then
to be in a single line

If(in_day.ToString.ToUpper.Equals(“FRIDAY”),DateTime.Now.AddDays(3),If(in_day.ToString.ToUpper.Equals(“SATURDAY”),DateTime.Now.AddDays(2),“Its not a weekend”))

hope this would help you
Cheers @HsDev

1 Like

may be in a assign activity with this single expression
out_date_string = If(in_day.ToString.ToUpper.Equals(“FRIDAY”),DateTime.Now.AddDays(3).DayOfWeek.ToString,If(in_day.ToString.ToUpper.Equals(“SATURDAY”),DateTime.Now.AddDays(2).DayOfWeek.ToString,“Its not a weekend”))

where this out_date_string is a string variable
cheers @HsDev

1 Like

Hi I’m a little confused with Switch. I’m looking for something similar using Switch also. If Day of the week is Monday then assign Friday (previous) otherwise yesterday.

I had the exact same issue

IF Monday then pull Fridays report (skip Sat, Sunday)
IF Tuesday-Friday pull one day prior

Switch made it easy, I just did each day as a case, and then “datetime.now.AddDays(-“enter number of backward days here”).ToString”

It can be a one liner but it will be messy.

If(dayofweek=“Saturday”,dateadd(2),if(dayofweek = “Sunday”,dateadd(1),Now))

This means if it’s saturday add 2 days, else process the second if which says if it’s Sunday add 1 day, otherwise just return today (Now). Note the above is pseudocode with the intent of just showing how an if expression works.

if(condition,do if true,do if false)

What I’ve done here is…

if(condition,Do if true,another if(condition,do if true,do if false))