Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make a date datatype accept 13 as a month and 30 for all months?

I am in Ethiopia and we have 13 months. 12 of them with 30 days each and 13th month with 5 or 6 days. I want to sort my data by date using the BindingSource sort method. But to do that, I need to set my date field a date data type. When I set the DataType to date, I can't enter some values like 13 for the month value and 30 for day value of 2nd month.

What I want is just to make my application accept 13 as a month and 30 as a day for all months, so that I can sort my data by date. Is it possible to do so by setting culture for my application or by some other means?

like image 489
Ashenafi Semu Avatar asked Feb 03 '10 14:02

Ashenafi Semu


1 Answers

In theory, you could load up the CultureInfo corresponding to language/country for Ethiopia. It appears that the native language in Ethiopia is Amharic which has ISO 639 short code of "am" and the ISO 3166 country code for Ethiopia is "ET". Thus, it appears that the correct culture code for Ethiopia is "am-ET". Thus, try the following.

CultureInfo ethiopia = new CultureInfo("am-ET");
int year = 2002; // it is currently 2002 in Ethiopia
int months = ethiopia.Calendar.GetMonthsInYear(year);
for (int i = 1; i <= months; i++) {
    Console.WriteLine(ethiopia.Calendar.GetDaysInMonth(year, i));
}

And then, as it is the 13th month that has five or days

DateTime time = new DateTime(2002, 13, 5, ethiopia.Calendar);

would be legal.

If for some reason that doesn't work, you could also look at how to create a custom calendar using this CodeProject on the Vietnamese Lunar Calendar as an example.

like image 133
jason Avatar answered Nov 16 '22 00:11

jason