*Note get DayOfWeek, Week In Month, Week In Year, Today Date, Today Month, Today Year, Today Time And Format.
Using
using System.Globalization;
Function
public static int Iso8601WeekNumber(DateTime dt)
{
System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
int weekNumOnMonth = ci.Calendar.GetWeekOfYear(dt, ci.DateTimeFormat.CalendarWeekRule, ci.DateTimeFormat.FirstDayOfWeek);
return weekNumOnMonth;
}
public static int GetWeekInMonth(DateTime date)
{
DateTime tempdate = date.AddDays(-date.Day + 1);
CultureInfo ciCurr = CultureInfo.CurrentCulture;
int weekNumStart = ciCurr.Calendar.GetWeekOfYear(tempdate, CalendarWeekRule.FirstFourDayWeek, ciCurr.DateTimeFormat.FirstDayOfWeek);
int weekNum = ciCurr.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, ciCurr.DateTimeFormat.FirstDayOfWeek);
return weekNum - weekNumStart + 1;
}
Eg.
WeekInYear = Iso8601WeekNumber(DateTime.Now); //This Year Week
WeekInMonth = GetWeekInMonth(DateTime.Now); //This Month Week
DayOfWeek = DateTime.Now.DayOfWeek.ToString(); //Day Of Week eg.Monday
MonthOnly = DateTime.Now.Month; //Today Month
DateOnly = DateTime.Now.Day; //Today Day
YearOnly = DateTime.Now.Year; //Today Year
TimeOnly2400 = DateTime.Now.ToString("HH:mm:ss tt"); //Now Time In 2400 Format
TimeOnly1200 = DateTime.Now.ToString("h:m tt"); //Now Time In 1200 Format
C# Get/Retrieve Week In Month And Week In Year
Posted by Unknown at 3/14/2013 01:56:00 pm
Labels: ASP.net C#
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment