Week day year in date format

I need to get the year when I use the format YYYY and the month MM , etc. I look to see if there is a format to get the week number of the year.

The date that I use as an example is 2008-03-09 16:05:07.000 , and I would like to know the week number, which in this case is 11 . Is there any way to get program code 11 ?

+6
source share
1 answer

There is no format that provides the week number, but you can easily get it as follows:

 System.Globalization.CultureInfo cul = System.Globalization.CultureInfo.CurrentCulture; int weekNum = cul.Calendar.GetWeekOfYear( DateTime.Now, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); 

To answer your comment, how to get a quarter of the year for a given DateTime :

 int quarter = (int)((DateTime.Now.Month - 1) / 3) + 1 
+21
source

Source: https://habr.com/ru/post/910123/


All Articles