Domanda

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

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top