1

I get "10/1/15 12:00:00 AM" time string from mysql db. How to convert this to a System.DateTime by the ParseExact method?

1
  • 2
    Are you sure that you get it as String? And not as already mapped DateTime? Commented Mar 13, 2016 at 9:35

1 Answer 1

2

You can use DateTime.ParseExact method with a custom date and time format.

I assume your 10 is as a day;

var dt = DateTime.ParseExact("10/1/15 12:00:00 AM", "dd/M/yy hh:mm:ss tt", 
                             CultureInfo.InvariantCulture);

By the way, of course saving your DateTime as a string in your database is a bad idea. Change your column type to DATETIME data type if you can.

Read: Bad habits to kick : choosing the wrong data type

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.