开发者

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

开发者 https://www.devze.com 2022-12-19 05:13 出处:网络
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

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消