Solved

convert string to date c#

Posted on 2013-11-25
2
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using sqldatareader to populate cells in Excel-syntax 6 21
Groupbox Control ? 2 27
Error building VS2105 solution from repository 1 33
Return array 3 19
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

740 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