HI i have a date let say 2020-02-14 how can i find next coming friday date which will be (2020-02-21)

can anybody help in this ?

static string GetNextFriday(DateTime dt)

{

int diff = (int)(dt.DayOfWeek - DayOfWeek.Friday);

var str = â€śâ€ť;

if (diff == 0)

{

str = â€śToday is Fridayâ€ť;

}

else if (diff < 0)

{

str = "Next friday is : " + dt.AddDays(Math.Abs(diff)).ToShortDateString();

}

else if (diff > 0)

{

str = "Next friday is : " + dt.AddDays(Math.Abs(6)).ToShortDateString();

}

return str;

}

//calling method

Console.WriteLine(GetNextFriday(DateTime.Now));

Console.WriteLine(GetNextFriday(new DateTime(2020,02,28)));

Console.WriteLine(GetNextFriday(new DateTime(2020, 03, 01)));

Hi,

Hope the following expression helps you.

```
dt.AddDays(if(dt.DayOfWeek<DayofWeek.Friday,DayOfWeek.Friday-dt.DayOfWeek,7-dt.DayOfWeek+DayOfWeek.Friday))
```

dt is datetime variable.

Regards,

Hi @goharmalik,

For this you can try this expression,

`date1.AddDays(5-Convert.ToInt32(date1.DayOfWeek))`

**Example** -

here date1 is DateTime variable.

`Convert.ToInt32(date1.DayOfWeek)`

â€”> this will convert DayOfWeek in number(letâ€™s take todayâ€™s date 2020/02/26, DayOfWeek is Wednesday then, itâ€™ll be 3)

As 5th day is friday, `(5-Convert.ToInt32(date1.DayOfWeek))`

â€”> 5-3 becomes 2.

`date1.AddDays(2)`

â€”> 2020/02/28 which is coming friday.

thatâ€™s it.

you can try below -

DateTime.Now.AddDays(7 - CInt(DayOfWeek.Friday))

Today - 26Feb

Output for Next Friday is 28Freb

@samir I have a doubt. When it is saturday, **(5-Convert.ToInt32(date1.DayOfWeek))** this returns -1 and wont it give previous friday rather than future date?

@samir Let suppose the date is 29/02/2020. This expression will give me the date of 28/02/2020 for Friday. The expression is expected to give next Friday but this will give past Friday.

hey @Sugumar8785, @goharmalik

try this,

```
If(date1.AddDays(5-CInt(Date1.DayOfWeek))<=date1,date1.AddDays(5-CInt(Date1.DayOfWeek)).AddDays(7),date1.AddDays(5-CInt(Date1.DayOfWeek)))
```

this will give to next coming Friday even if given date day is Friday.

it is working thanks

it worked

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