PM's Blog

Pramod Mohanan's notes about ASP.NET, MVC, C#, SQL, jQuery, Bootstrap

Unable to convert MySQL date/time value to System.DateTime

While filling a .Net DataSet with data from MySql, date fields can cause the error

Unable to convert MySQL date/time value to System.DateTime

After some research, I found a solution to this issue is to use DATE_FORMAT in the select statement like below

SELECT
    FirstName, LastName,
    DATE_FORMAT(RegistrationDate, '%d/%m/%Y') AS DateOfRegistration,
    UserName
FROM tblUsers

Leave a Reply

Your email address will not be published. Required fields are marked *

PM's Blog © 2015