I'm currently using this snippet:
private string GetCurrentWeek()
{
// Return a string to be used in the TextBox control on the Main Form
DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
int Year = DateTime.Now.Year;
int Month = DateTime.Now.Month;
int Day = DateTime.Now.Day;
DateTime Date1 = new DateTime(Year, Month, Day);
Calendar cal = dfi.Calendar;
return cal.GetWeekOfYear(Date1, dfi.CalendarWeekRule, dfi.FirstDayOfWeek).ToString();
}
To get the current week of the year. Which returns as expected. Though. This is starting from January. Which is doing what the code says. Though, I'm ideally looking for it to start from April. So week 1 would start on the 6th of April and Week 52 would be on April 5th (just like the UK Tax Year). I have sought the internet and google (perhaps using wrong keywords) but I'm unable to discover how to perform this task using C#
I'm assuming you want week 1 to begin on April 6th always, and be 7 days long, rather than having some rule like "Weeks always start on Mondays". Basically this is just a matter of:
For example:
Of course, you could also use Noda Time: