Solved

convert string to date c#

Posted on 2013-11-25
2
403 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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