ASP.NET: DATE, Calculate Week Start Date

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(“alert(‘” + ws + “‘)”);
        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;
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s