Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to convert int month & year to string month & year.

C#
like "08/2014" to "Aug 2014"



Thanks,
Posted

C#
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(<int>)</int>


So
C#
string[] date = "08/2014".Split('/');
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(date[0]));
 
Share this answer
 
Convert.ToDateTime("08 01 2014").ToString("MMM yyyy");
 
Share this answer
 
v2
If your starting point is a string containing "MM/yyyy" convert it to a datetime using DateTime.TryParse[^] - if it is two numbers use the datetime constructor that takes year,month,day and use 1 for day.

To convert this to the string you want use DateTime.ToString(@"MMM yyyy")[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900