Get Date from Week Number
Code .NET SQL :: ASP.NET :: C#
Page 1 sur 1
Get Date from Week Number
- Code:
string month = GetFirstDayOfWeek(weekNumber, dateTime.ToString("MMMM");
- Code:
public DateTime GetFirstDayOfWeek(int year, int weekNumber, DayOfWeek dayOfWeek)
{
return GetLastOccurenceOfDay(new DateTime(year, 1, 1).AddDays(7 * weekNumber), dayOfWeek);
}
public DateTime GetFirstDayOfWeek(int weekNumber,int Year)
{
return GetFirstDayOfWeek(Year, weekNumber, DayOfWeek.Monday);
}
- Code:
public DateTime GetLastOccurenceOfDay(DateTime value, DayOfWeek dayOfWeek)
{
int daysToAdd = dayOfWeek - value.DayOfWeek;
if (daysToAdd < 1)
{
daysToAdd -= 7;
}
return value.AddDays(daysToAdd);
}
Code .NET SQL :: ASP.NET :: C#
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum