Solved

convert string to date c#

Posted on 2013-11-25
2
394 Views
Last Modified: 2013-11-26
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?
0
Comment
Question by:JonMny
2 Comments
 
LVL 19

Accepted Solution

by:
Rikin Shah earned 500 total points
ID: 39676725
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
 
LVL 40
ID: 39677614
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now