Last post Sep 24, 2014 01:27 PM by wavemaster
Sep 24, 2014 01:05 PM|wavemaster|LINK
Where is this coming from?
int calwid = 7;
DateTime theday = DateUtils.DaysToAdd(DayOfWeek.Wednesday, DayOfWeek.Tuesday, calwid);
public class DateUtils
public static int GetWeekNo(DateTime date)
System.Globalization.CultureInfo cult_info = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
System.Globalization.Calendar cal = cult_info.Calendar;
int weekCount = cal.GetWeekOfYear(date, cult_info.DateTimeFormat.CalendarWeekRule, cult_info.DateTimeFormat.FirstDayOfWeek);
public static int DaysToAdd( DayOfWeek current, DayOfWeek desired, int calwid )
// f( c, d ) = g( c, d ) mod 7, g( c, d ) > 7
// = g( c, d ), g( c, d ) < = 7
// where 0 <= c < 7 and 0 <= d < 7
int c = (int)current;
int d = (int)desired;
int w = (int)calwid;
int n = (w - c + d);
return (n > 7) ? n % 7 : n;
public static DateTime GetNextDateForDay( DateTime startDate, DayOfWeek desiredDay, int calwid )
// Given a date and day of week,
// find the next date whose day of the week equals the specified day of the week.
return startDate.AddDays( DaysToAdd( startDate.DayOfWeek, desiredDay, calwid ) );
Sep 24, 2014 01:14 PM|PatriceSc|LINK
DaysToAdd returns an int and you try to assign this integer to a DateTime... Could it be that you rather wanted to use GetNextDateForDay ???
Sep 24, 2014 01:27 PM|wavemaster|LINK
The call should have been made like this:
DateTime theday = DateUtils.GetNextDateForDay(DateTime.Today, DayOfWeek.Tuesday, calwid);
Now I get the best overloaded match for...
What I want is to find the date for a day (for instance Tuesday), either next week, or the week after. The argument for the sample are:
Today, Tuesday, 7 or 14
I am lost.