Reputation: 103
1) How do I find Current Week from Current Date time in C#?
2) Then we have to find given date, Is Exist on corresponding Week dates?
Pls assists to me for solve it?
Upvotes: 0
Views: 1404
Reputation: 836
To get week number of any given date:
var culture = CultureInfo.CurrentCulture;
int weekNo = culture.Calendar.GetWeekOfYear(
new DateTime(YOUR_GIVEN_DATE_HERE),
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);
Just replace YOUR_GIVEN_DATE_HERE with Datetime.Now (for current date) or your any given date. If the weekNos are equal then they are in the same week. That will solve both of your questions.
Upvotes: 0
Reputation: 956
You have to use a 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
Upvotes: 0