Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one,

i want to convert the date format mmddyy to mm/dd/yy. i,e(03252015 to 03/25/2015).

i have searched in google i tired all the methods.it's showing the error msg like this.
"string is not a valid datetime".

any one help me please.
Posted

 
Share this answer
 
Comments
Aarti Meswania 25-Mar-14 8:11am    
5+! :)
Assuming you want a string result:
C#
private string forceDateFormat(string sourceString)
{
    return DateTime.ParseExact(sourceString, "mmddyyyy", DateTimeFormatInfo.InvariantInfo).ToString(@"mm\/dd\/yyyy");
}

//example of use:
string convertedDate = forceDateFormat("03252015");
 
Share this answer
 
try this.. :)


C#
string res = "03252015";
DateTime d = DateTime.ParseExact(res, "MMddyyyy", CultureInfo.InvariantCulture);
Console.WriteLine(d.ToString("MM/dd/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