Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I get this error:

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

while I am trying to fetch the data from a MySQL database. I have the date datatype in my MySQL database. But while retrieving it into my datatable, it get the error above.

How can I fix this?

like image 996
Ankit Chauhan Avatar asked Apr 22 '11 11:04

Ankit Chauhan


People also ask

How do I change datetime to date in MySQL?

Here is the query to convert from datetime to date in MySQL. mysql> select cast(ArrivalDatetime as Date) as Date from ConvertDateTimeToDate; The following is the output.

Does MySQL store datetime as UTC?

MySQL Column Types Range: 1970-01-01 00:00:01 to 2038-01-19 03:14:07 for TIMESTAMP ; 1000-01-01 to 9999-12-31 for DATETIME . Time zones: TIMESTAMP values will be converted to UTC for storage and from UTC for retrieval, which can lead to reading different values.

What is the datetime format in MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

Can we change date format in MySQL?

MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't. Instead, you follow the standard date format and use the DATE_FORMAT function to format the date the way you want.


1 Answers

You must add Convert Zero Datetime=True to your connection string, for example:

server=localhost;User Id=root;password=mautauaja;Persist Security Info=True;database=test;Convert Zero Datetime=True 
like image 167
agni Avatar answered Sep 18 '22 17:09

agni