Question

I'm working in ASP using MVC 4, and i try to know the number of week in month. For example, the user inserts 05/02/2014, and i in controller needs to know the number of week from this date. For example: The user insert 04/02/2014 and i gets result 6

Edit: Using format dd/mm/yyyy

Was it helpful?

Solution

This should solve your problem -

UPDATED With string DateTime conversion

DateTime dt = DateTime.ParseExact("28/02/2014","dd/MM/yyyy", CultureInfo.InvariantCulture);
var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
cal.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top