convert string to date c#

I have dates like this

"2013-12-25 00:30"
"2013-12-25 01:30"

Need to convert to dateTime in c#. How can i do this?
LVL 9
JonMnyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Rikin ShahConnect With a Mentor Microsoft Dynamics CRM ConsultantCommented:
Hi,

Have you tried these?
Convert.ToDateTime(DateString);

Or
DateTime myDate = DateTime.ParseExact("2013-12-25 00:30", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
rikin_shah shows you the way to do it, but only in the second part of his answer, by calling ParseExact.

Convert.ToDateTime is always dangerous to use because it takes into account the format of the date as defined in the Control Panel, and this can change from one computer to another. You might test it on your computer and it works, only to break on one of your users computer. It can be used for dates typed in by the user, but never for dates that come from files or that a database returns as a fixed string format.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.