Find the current week from Datetime.Now and how to find the given date between the dates of the current week?

1) How to find the current week from the current date in C #?

2) Then we have to find the given date, Is Exist on the corresponding dates of the week?

Pls help me solve it?

0
source share
3 answers
int currentWeek = (DateTime.Now.DayOfYear / 7) + 1;
+3
source

You must use the Calendar.

Calendar cal = new Calendar();
int week = cal.GetWeekOfYear(DateTime time, calendarWeekRule rule, DayOfWeek firstDayOfWeek);

Check here: http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear(v=vs.110).aspx

0
source

:

var culture = CultureInfo.CurrentCulture;
int weekNo = culture.Calendar.GetWeekOfYear(
            new DateTime(YOUR_GIVEN_DATE_HERE),
            currentCulture.DateTimeFormat.CalendarWeekRule,
            currentCulture.DateTimeFormat.FirstDayOfWeek);

YOUR_GIVEN_DATE_HERE Datetime.Now( ) . weekNos , . .

0

All Articles