Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I convert '29-04-2012' in following format '29-Apr-2012'

I am using following code

String.Format("{0:DD,MMM,YYYY}",date)


but its not working

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 26-Apr-12 21:28pm
v2
Comments
OriginalGriff 27-Apr-12 3:28am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
djrocks0101 27-Apr-12 3:30am    
ok...

Convert it to a DateTime and then back to a string:
C#
DateTime dt = DateTime.ParseExact("29-04-2012", "dd-MM-yyyy", CultureInfo.InvariantCulture);
string str = dt.ToString("dd.MMMM.yyyy");

Try to always keep dates in DateTime format rather than string - convert from string as early as possible, and convert back to string as late as possible. Most systems will work with a DateTime without getting confused by the date format the user entered it in!
 
Share this answer
 
Comments
sravani.v 27-Apr-12 4:13am    
MY 5!
(__Aaron__) 27-Apr-12 5:21am    
my 5
Try this:
C#
DateTime date = DateTime.ParseExact("29-04-2012", "dd-MM-yyyy",
                 System.Globalization.CultureInfo.InvariantCulture);
 
Share this answer
 
Comments
sravani.v 27-Apr-12 4:13am    
MY 5!
Prasad_Kulkarni 27-Apr-12 4:47am    
Thank You!

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