Tuesday, January 27, 2009

Specified time is not supported in this calendar. It should be between 07/18/0622 00:00:00 (Gregorian date) and 12/31/9999 23:59:59 (Gregorian date),

I was working on the "arabic culture" Sharepoint web application in which i need to filter the news by datecontrol.

The error i was getting was:
Specified time is not supported in this calendar. It should be between 07/18/0622 00:00:00 (Gregorian date) and 12/31/9999 23:59:59 (Gregorian date),

It was because the DateTime Control tries to initialize the arabic date becuase the main thread has arabic culture. The solution was simple. Change the Thread Culture during initalization.

CultureInfo ciEng = new CultureInfo("en-US");
CultureInfo ciAr = new CultureInfo("ar-SA");


Thread.CurrentThread.CurrentCulture = ciEng;

Code

Thread.CurrentThread.CurrentCulture = ciAr;

If any one of the reader has some other approaches, kindly post here.