Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

convert string to date c#

Posted on 2013-11-25
2
Medium Priority
?
428 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 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