0
Posted on 1:02 AM by Softminer and filed under

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace WebApplication1.DateOfWeek
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string ret = GetStringFromWeek();
        }
 
        private string GetStringFromWeek()
        {
            var d = DateTime.Now;
            System.Globalization.CultureInfo cul = System.Globalization.CultureInfo.CurrentCulture;
            var firstDayWeek = cul.Calendar.GetWeekOfYear(
                d,
                System.Globalization.CalendarWeekRule.FirstDay,
                DayOfWeek.Monday);
            int weekNum = cul.Calendar.GetWeekOfYear(
                d,
                System.Globalization.CalendarWeekRule.FirstFourDayWeek,
                DayOfWeek.Monday);
            int year = weekNum == 52 && d.Month == 1 ? d.Year - 1 : d.Year;
 
            switch(weekNum)
            {
                case 4: return "MA";
                case 5: return "MB";
                case 6: return "MB";
                case 7: return "MB";
                case 8: return "MB";
                case 9: return "MB";
                case 10: return "MB";
                case 11: return "MB";
                case 12: return "MB";
                case 13: return "MB";
                case 14: return "MB";
                case 15: return "MB";
                case 16: return "MB";
                case 17: return "MB";
                case 18: return "MB";
                case 19: return "MB";
                case 20: return "MB";
                case 21: return "MB";
                case 22: return "MB";
                case 23: return "MB";
                case 24: return "MB";
                case 25: return "MB";
                case 26: return "MB";
                case 27: return "MB";
                case 28: return "MB";
                case 29: return "MB";
                case 30: return "MB";
                case 31: return "MB";
                case 32: return "MB";
                case 33: return "MB";
                case 34: return "MB";
                case 35: return "MB";
                case 36: return "MB";
                case 37: return "MB";
                case 38: return "MB";
                case 39: return "MB";
                case 40: return "MB";
                case 41: return "MB";
                case 42: return "MB";
                case 43: return "MB";
                case 44: return "MB";
                case 45: return "MB";
                case 46: return "MB";
                case 47: return "MB";
                case 48: return "MB";
                case 49: return "MB";
                case 50: return "MB";
                case 51: return "MB";
                case 52: return "MB";
                default: return "Default";
        
 
            }
 
            return "test";
        }
 
 
        private string GetDayoFWeek()
        {
            switch (DateTime.Now.DayOfWeek)
            {
                case DayOfWeek.Friday:
                    return "F";
                case DayOfWeek.Monday:
                    return "M";
                case DayOfWeek.Saturday:
                    return "S";
                case DayOfWeek.Sunday:
                    return "M";
                case DayOfWeek.Thursday:
                    return "T";
                case DayOfWeek.Tuesday:
                    return "E";
                case DayOfWeek.Wednesday:
                    return "W";
            }
            return "NO";
        }
        
    }
}
0
Responses to ... Week of the year