Geeks With Blogs
Moez Mousavi

The Current week dates

Might be a bit weird as we normaly not writing a multicultural web site. So not very frequently using CultureInfo however, it is  actully quite good to use it to get the week days. Seems the class has got some issues in .NET 2.0 as it was not picking the first day of the week correctly, I have used the below code in 3.5 and it does work.

 

CultureInfo info = Thread.CurrentThread.CurrentCulture;

DayOfWeek firstday = info.DateTimeFormat.FirstDayOfWeek;

DayOfWeek today = info.Calendar.GetDayOfWeek(DateTime.Now);


int diff = today - firstday;

DateTime firstDate = DateTime.Now.AddDays(-diff);

DateTime lastDate = firstDate.AddDays(6);

 

Posted on Thursday, December 16, 2010 11:37 PM C# | Back to top

Copyright © MoezMousavi | Powered by: GeeksWithBlogs.net