Click here to Skip to main content
15,665,942 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

This may be a widely asked question with lots of possible solutions but unfortunately none of them is working for me..

I have a string like this:
"02/09/2015 10:00"
which represents
dd/mm/yyyy HH:mm

I have tried using Convert.toDateTime() and DateTime.Parse() There is no error, but it always gives output which says its 09th Feb, 2015 which is not. The time part is alright though.

How can I get correct output?

Thank you....
CHill60 2-Sep-15 8:46am    
What code are you using to produce the output?
Andy Lanng 2-Sep-15 8:48am    
Try DateTime.ParseExact
Ralf Meier 2-Sep-15 8:52am    
Have you tried to write it like this : "dd/MM/yyyy HH:mm" instead of "dd/mm/yyyy HH:mm"
Sergey Alexandrovich Kryukov 2-Sep-15 8:55am    
What's wrong with reading original MSDN documentation?
Andy Lanng 2-Sep-15 8:57am    
Ha - virtual 5*

1 solution

First of all, think at this: can you totally avoid "conversion" (in fact, parsing) strings? This is usually possible, if your learn to work with data, not strings representing data.

To parse correctly, you just need to look at all available DateTime parse methods, not only Parse, but TryParse, ParseExact and TryParseExact. You will see parameters used to specify the culture and/or exact format:[^],[^],[^],[^].

For formats, please see:[^],[^].

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