Click here to Skip to main content
15,902,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am unable to convert Date format "yy/MM/dd" by using convert.toDateTime()

it throws exception "String was not recognized as a valid DateTime."

Please help.

Thanks
Posted

Use DateTime.TryParse[^] to parse date and time.
 
Share this answer
 
Comments
Member 11449483 3-Feb-16 1:59am    
sorry not working.
What is not working? What have you tried exactly?
C#
string date = "16/02/03";

DateTime dt;

if (!DateTime.TryParseExact(
    date,
    "yy/MM/dd",
    System.Globalization.CultureInfo.CurrentCulture,
    System.Globalization.DateTimeStyles.None,
    out dt))
{
    // conversion didn't work
}

System.Diagnostics.Debug.WriteLine(dt);
 
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