In VB6 code, I have the following:
dim I as Long
I = Weekday(Now, vbFriday)
I want the equivalent in C#. Can any one help?
public static int Weekday(DateTime dt, DayOfWeek startOfWeek)
{
return (dt.DayOfWeek - startOfWeek + 7) % 7;
}
This can be called using:
DateTime dt = DateTime.Now;
Console.WriteLine(Weekday(dt, DayOfWeek.Friday));
The above outputs:
4
as Tuesday is 4 days after Friday.