Getting an error while executing a SELECT statement in Toad for MySQL

I get this error while I try to execute a simple SELECT statement in Toad

MySql.Data.Types.MySqlConversionException Unable to convert MySQL date/time value to System.DateTime 

What could be wrong?

+4
source share
1 answer

This can mean one of two common problems:

1) Zero dates that are 0000-00-00 in MySQL. MySQL allows you to store them for 0 dates, you can even use 0001-01-01, but not all drivers or downstream programs can handle them. Add to connection string

 Allow Zero Datetime=true; 

Another choice explicitly removes them, something like

 SELECT IF(DateCol='0000-00-00' OR DateCol<'1970-01-01', NULL, DateCol) as DateCol, Othercol1, ID .... FROM TBL 

2) Date formatting. For some combinations of drivers and programs, these dates are treated as strings. Explicit conversion required:

 SELECT DATE_FORMAT(DateCol, '%m/%d/%Y') as DateCol, Othercol1, ID .... FROM TBL 
+4
source

Source: https://habr.com/ru/post/1340926/


All Articles