Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am using ibatis and C#. i get a result from a select query that has CreatedDate as one of the field. The Datatype of CreatedDate in Mysql is Date. I assign the result set of the select query to a Ilist< DeliveryClass>.

Here the DeliveryClass CreatedDate as DateTime. When i run the application, i get Unable to convert MySQL date/time value to System.DateTime. What could be the problem?

like image 499
Gopi Avatar asked May 29 '10 11:05

Gopi


People also ask

How do I insert date in YYYY-MM-DD format in MySQL?

You can use str_to_date to convert a date string to MySQL's internal date format for inserting.

Is MySQL datetime UTC?

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME .) By default, the current time zone for each connection is the server's time.

How do you display time and date in MySQL?

The CURRENT_TIMESTAMP function in the MySQL database returns the current date and time (i.e. the time for the machine running that instance of MySQL). It is given as a value in the 'YYYY-MM-DD hh:mm:ss' format.

What is the fix format of date statement in MySQL?

Introduction to MySQL DATE data type MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it.


2 Answers

MySqlConnection connect = new MySqlConnection("server=localhost; database=luttop; user=root; password=1234; pooling = false; convert zero datetime=True"); 

Adding convert zero datetime=True to the connection string will automatically convert 0000-00-00 Date values to DateTime.MinValue().

that's SOLVED

like image 171
levefdsa Avatar answered Sep 22 '22 02:09

levefdsa


Adding "convert zero datetime=True" to the connection string solved my problem.

<connectionStrings>   <add name="MyContext" connectionString="Datasource=localhost;Database=MyAppDb;Uid=root;Pwd=root;CHARSET=utf8;convert zero datetime=True" providerName="MySql.Data.MySqlClient" /> </connectionStrings> 

Regards PS

like image 23
WeezHard Avatar answered Sep 20 '22 02:09

WeezHard