DateTime ws = weekStartDay();
wsLabel.Text = ws.ToString("d");
//.ToString(“d”) will format the string as date
private DateTime weekStartDay()
{
DateTime ws = DateTime.Now;
string day = DateTime.Now.DayOfWeek.ToString();
//Response.Write("<script>alert('" + ws +
"')</script>");
switch (day)
{
case "Monday":
ws = ws.AddDays(0);
break;
case "Tuesday":
ws = ws.AddDays(-1);
break;
case "Wednesday":
ws = ws.AddDays(-2);
break;
case "Thursday":
ws = ws.AddDays(-3);
break;
case "Friday":
ws = ws.AddDays(-4);
break;
case "Saturday":
ws = ws.AddDays(2);
break;
case "Sunday":
ws = ws.AddDays(1);
break;
}
return ws;
}
No comments:
Post a Comment