Monday, 21 June 2021

How To Get the Month Number From Month Name in C# | Convert month name to month number in C#.net

Month Number From Full Month Name 

If we need Month Number From Full Month Name then use below code
string monthName = "April";
int monthNumber = DateTime.ParseExact(monthName, "MMMM", CultureInfo.CurrentCulture).Month;

Month Number From Month Abbreviations

If we need to convert a month number from a month abbreviations then use below code
string monthName = "Apr";
int monthNumber = DateTime.ParseExact(monthName, "MMM", CultureInfo.CurrentCulture).Month;

3 comments:

Related Posts Plugin for WordPress, Blogger...

ShareThis