I am using ASP:Calendar in ASP.NET Website. I need to retrieve DayofWeek whether 1stSunday,2nd Sunday,3rd Sunday or 4th Sunday similarly for other days of that month for the date selected. Kindly help in this. thanks in advance.
Asked
Active
Viewed 2,060 times
0
-
refer this http://stackoverflow.com/a/1497620/1239554 – shanish Feb 27 '14 at 09:08
-
@shanish I need week of month. The link has week of year. – Chetan Goenka Feb 27 '14 at 09:28
3 Answers
0
You probably already have DateTime variable. If yes, you can use this code to calculate week number:
var currentCulture = CultureInfo.CurrentCulture;
var weekNo = currentCulture.Calendar.GetWeekOfYear(
new DateTime(2013, 12, 31), //Your date
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);
Good luck!

Nancy
- 1
- 3
0
Here is example from MSDN:
public class Example
{
public static void Main()
{
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
DateTime date1 = new DateTime(2011, 1, 1);
Calendar cal = dfi.Calendar;
Console.WriteLine("{0:d}: Week {1} ({2})", date1,
cal.GetWeekOfYear(date1, dfi.CalendarWeekRule,
dfi.FirstDayOfWeek),
cal.ToString().Substring(cal.ToString().LastIndexOf(".") + 1));
}
}
And also the link: http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear.aspx

user3359717
- 1
- 2
0
I did the following in one of my projects to get current week number in a month
private static int GetWeekNum(DateTime date, CultureInfo culture)
{
var firstOfMonth = new DateTime(date.Year, date.Month, 1);
return GetWeekNumber(date, culture) - GetWeekNumber(firstOfMonth, culture) + 1;
}
private static int GetWeekNumber(DateTime date, CultureInfo culture)
{
return culture.Calendar.GetWeekOfYear(date,
culture.DateTimeFormat.CalendarWeekRule,
culture.DateTimeFormat.FirstDayOfWeek);
}

HCJ
- 529
- 1
- 6
- 14