Click here to Skip to main content
16,016,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (userDateFormat.Trim().Contains("dd/MM/yyyy"))
    convertedDateTime = DateTime.ParseExact(dateTimeString,
        format_dmy,
        CultureInfo.InvariantCulture,
        DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite);
Posted
Updated 22-Mar-15 23:22pm
v3
Comments
[no name] 18-Mar-15 2:02am    
Which line u got the error?
Maciej Los 18-Mar-15 2:43am    
?
deepankarbhatnagar 23-Mar-15 0:39am    
Where is the error comes?

1 solution

Assuming that the second line is the one that threw the exception, you should probably use the safer error checking version of the DateTime parser...

https://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact%28v=vs.110%29.aspx[^]

This will allow you to use the same values, but you pass the instance of your convertedDateTime as the final parameter in the method as "out convertedDateTime" and you can check the returned Boolean value to see if your conversion was successful.
 
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