Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
int month;
month = System.DateTime.Now.Month;

I am trying to get the current month value in the format 'Apr' but have been able to get in number format only.I am working on a web application.Tried using ToString


Regards,
Madhu
Posted
Updated 25-Apr-11 0:20am
v2

Try this,
string strMonth = System.DateTime.Now.ToString("MMM");
 
Share this answer
 
Comments
Ankur\m/ 25-Apr-11 6:28am    
That should help, 5!
Toniyo Jackson 25-Apr-11 7:31am    
Thanks Ankur
[no name] 25-Apr-11 6:29am    
Nice one my 5++
Toniyo Jackson 25-Apr-11 7:31am    
Thanks Santosh
Nish Nishant 25-Apr-11 9:00am    
Voted 5.
This answer is simple and should be obvious. There are two methods of which one uses custom formats and another more easily editable solution.

1)
string Month = System.DateTime.Now.ToString("MMM");


2) Create a string array with all the names of the months and then simply index into it with System.DateTime.Now.Month to get month string you wanted. You might want to check whether January comes out as 0 or 1 and if the latter subtract 1 before indexing into the array.
 
Share this answer
 
v3
Comments
[no name] 25-Apr-11 6:29am    
nice one my 5++
Ed Nutting 25-Apr-11 6:30am    
Thanks :)
string srrMonth= system.dateTime.Now.ToString("MMM");
 
Share this answer
 
v2

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