9

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?

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Ashenafi Semu
  • 149
  • 1
  • 1
  • 10
  • what language/framework are you using? (ex. VB.Net, Java etc.) – Patrick Karcher Feb 03 '10 at 14:14
  • What, exactly, is stopping you from entering a 13? Is it the database or some other code? – NotMe Feb 03 '10 at 14:24
  • i set the database field to string and it is okay! But i set the datatable's field to date on the dataset designer. It says could not store 13062000 in date column at Me.Table1TableAdapter.Fill(Me.Database2DataSet.Table1) – Ashenafi Semu Feb 03 '10 at 14:34

2 Answers2

3

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.

jason
  • 236,483
  • 35
  • 423
  • 525
  • 1
    The Ethiopic numbering system is fascinating as it does not have a zero: http://blogs.msdn.com/michkap/archive/2005/02/01/364376.aspx – jason Feb 03 '10 at 14:34
  • How can I do this to change the datatable? I mean it is the datatable that's not accepting the data coming from the database. – Ashenafi Semu Feb 03 '10 at 14:47
  • Try setting the `DataTable.Locale` property to an instance of `CultureInfo` that represents the "am-ET" culture. I don't know that will work, but it's the first thing to try. The problem is that the `DataTable` will still use the `InvariantCulture` for a vast majority of its functionality. – jason Feb 03 '10 at 14:53
  • 1
    setting the locale of the datatable changes nothing. also "am-ET" is not a valid culture name. it seems that ethiopia is not in the caltureinfo culture list. can you show me how to create a custom calendar, the link you gave me is not clear. – Ashenafi Semu Feb 04 '10 at 11:49
0

I used this as a solution.

you could add a separate column in your datatable to account for the extra epagomenal days... then sort your data by both columns. for instance: here would be a sample table sorted descending first by Column1 then by Column2:

RegDate----------------EpaDate

12/30/09--------------- 1/5/2010 12/30/09----------------1/4/2010 12/30/09----------------1/3/2010 12/30/09----------------1/2/2010 12/30/09----------------1/1/2010 12/30/09------------------NULL 12/29/09------------------NULL 12/28/09------------------NULL

Ashenafi Semu
  • 149
  • 1
  • 1
  • 10