Equivalent of WeekDay Function of VB6 in C#
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. You mean the DateTime.DayOfWeek property? DayOfWeek dow = DateTime.Now.DayOfWeek; Yes, Each DateTime value has a built in property called DayOfWeek that returns a enumeration of the same name... DayOfWeek