Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there built-in Month name declensions in C#

I'm wondering if there's any built-in functionality in .NET for declining dates in languages that support noun declensions, (ie. In Russian the month name is февраль, but if I wanted to say the date or say that something is due by, I'd use the form февраля). I made my own version, which works for this case, but I will need to expand to to other cases, and other languages, which will have their own declensions for dates.

Is this functionality built-in, or available in an external library? Thank you for any help.

I've provided my function for the Russian genitive case, if my explanation wasn't clear.

public static string DeclineMonth(this DateTime time) {     var month = time.ToString("MMMM");     if (month.Last() == 'ь')         return month.Replace('ь', 'я');     else         return month + "a"; }        
like image 336
Kolichikov Avatar asked Feb 09 '17 09:02

Kolichikov


People also ask

How to get month name from date in linq?

Write simple select query and use DateTime structure . ToString("MMMM") method to get month name.


1 Answers

You can obtain months' names in two cases, Nominative:

DateTimeFormatInfo info = CultureInfo.GetCultureInfo("ru-RU").DateTimeFormat;  // February: 2 - 1 (array is zero based) - "Февраль" Console.Write(info.MonthNames[2 - 1]); 

And Genitive:

// February: 2 - 1 (array is zero based) - "февраля" Console.Write(info.MonthGenitiveNames[2 - 1]); 

Other cases (e.g. Dative, Accusative) are not supported and we have to implement them manually.

like image 113
Dmitry Bychenko Avatar answered Sep 24 '22 23:09

Dmitry Bychenko