Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to Convert a Date String with Format “MM dd,yyyy” to yyyy-mmdd

What I have tried:

C#
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dateTime = DateTime.ParseExact(incorporate, "MM dd,yyyy", provider);
Posted
Updated 16-Dec-20 21:48pm
v2
Comments
BillWoodruff 17-Dec-20 1:28am    
Come back when you have actually tried something: see all those "Related Questions" links on this page ? Study a few of them.

Well, you haven't posted any code, so really you've got diddly-squat .. I suggest you start reading here, Convert strings to DateTime | Microsoft Docs[^] with a view to using DateTime.ParseExact()
 
Share this answer
 
Comments
Gokulprasad05 17-Dec-20 1:29am    
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dateTime = DateTime.ParseExact(incorporate, "MM dd,yyyy", provider);
Instead of using ParseExact, use TryParseExact:
C#
string incorporate = "03 27,1954";
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime dt;
if (!DateTime.TryParseExact(incorporate, "MM dd,yyyy", provider, DateTimeStyles.None, out dt))
    {
    ... report problem to user ...
    return;
    }
string formatted = dt.ToString("yyyy-MMdd");
 
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