Display Monday and Sunday of current week


/// <summary>
/// Returns first day of current week i.e. monday.
/// </summary>
        private void FirstDayOfWeek()
        {
            DateTime FirstDayOfWeek = DateTime.Now;
            DayOfWeek WeekDay = FirstDayOfWeek.DayOfWeek;
            switch (WeekDay)
            {
                case DayOfWeek.Monday:
                    break;
                case DayOfWeek.Tuesday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-1);
                    break;
                case DayOfWeek.Wednesday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-2);
                    break;
                case DayOfWeek.Thursday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-3);
                    break;
                case DayOfWeek.Friday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-4);
                    break;
                case DayOfWeek.Saturday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-5);
                    break;
                case DayOfWeek.Sunday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-6);
                    break;

            }
            this.txtScheduledFrom.Text = FirstDayOfWeek.ToString(“MM/dd/yyyy”);
        }

 

/// <summary>
/// Returns first day of current week i.e. monday.
/// </summary>

        private void FirstDayOfWeek()
        {
            DateTime FirstDayOfWeek = DateTime.Now;
            DayOfWeek WeekDay = FirstDayOfWeek.DayOfWeek;
            switch (WeekDay)
            {
                case DayOfWeek.Monday:
                    break;
                case DayOfWeek.Tuesday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-1);
                    break;
                case DayOfWeek.Wednesday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-2);
                    break;
                case DayOfWeek.Thursday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-3);
                    break;
                case DayOfWeek.Friday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-4);
                    break;
                case DayOfWeek.Saturday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-5);
                    break;
                case DayOfWeek.Sunday:
                    FirstDayOfWeek = FirstDayOfWeek.AddDays(-6);
                    break;

            }
            this.txtScheduledFrom.Text = FirstDayOfWeek.ToString(“MM/dd/yyyy”);
        }

Advertisements

Leave a Comment

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