Ljhopkins

In sql I can find the monday date of any given date with the following

select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)

I need to rename the header text of 30 col to be the monday date for the prev week, this week,

this week+1, +2..... this week +30

but there is no week value for an interval

please help



Re: Windows Forms General finding the monday date of a given date

nobugz

Try something like this:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
public static DateTime MondayDate(DateTime date, int weeks) {
// Returns the date of the next Monday, offset by <weeks>
int dayofweek = (int)date.DayOfWeek;
int days = 0;
if (dayofweek == 0) days = 1;
else if (dayofweek != 1) days = 8 - dayofweek;
days += weeks * 7;
return date + new TimeSpan(days, 0, 0, 0);
}

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) {
DateTime date = MondayDate(monthCalendar1.SelectionStart, (int)numericUpDown1.Value);
Console.WriteLine(date.ToString());
}






Re: Windows Forms General finding the monday date of a given date

Ljhopkins

Dim y As Date = DateAdd(DateInterval.Day, 1 - DatePart(DateInterval.Weekday, Today(), FirstDayOfWeek.Monday), Today())

Dim z As String = DateAdd(DateInterval.Day, -7, y)