0

My code:

DateTime tupdated1;  
tupdated1 = reader.GetDateTime("tupdated");

I got some error about:

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

How can i get timestamp (last updated) from mysql in C#?

Please release me!

biruk1230
  • 3,042
  • 4
  • 16
  • 29
Jalol
  • 23
  • 5
  • 1
    What is the type of the MySQL `tupdated` column? – Tim Biegeleisen Jan 28 '20 at 13:08
  • 1
    Hey, please attach a minimal code on your question, and check this out: https://stackoverflow.com/questions/54792728/unable-to-convert-mysql-date-time-value-to-system-datetime-when-not-using-a-da it's very similar – boolean Jan 28 '20 at 13:10
  • this is TIMESTAMP type – Jalol Jan 28 '20 at 13:18
  • Does this answer your question? [Unable to convert MySQL date/time value to System.DateTime](https://stackoverflow.com/questions/2934844/unable-to-convert-mysql-date-time-value-to-system-datetime) – Marco Salerno Jan 28 '20 at 13:37
  • Does the field contain any invalid values like `0000-00-00`? There's no 0 date. That's a quasi-*un*supported MySQL weirdness - [quasi-unsupported by MySQL itself](https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_zero_date) that is. – Panagiotis Kanavos Jan 28 '20 at 13:37
  • Another possibility is an illegal date like `2010-04-31` if [ALLOW_INVALID_DATES](https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_allow_invalid_dates) is set. Depending on *other* settings, this can be allowed or converted to `0000-00-00` – Panagiotis Kanavos Jan 28 '20 at 13:40
  • Thank you very much for your help to me it works! – Jalol Jan 28 '20 at 13:51
  • @MarcoSalerno the accepted answer isn't a good one - dates have no format. The upvoted answer is a lot better though and could actually help – Panagiotis Kanavos Jan 28 '20 at 13:51

2 Answers2

0

First Check your DB datasheet data type.

My guess is your wrong use data type.

DateTime is right data type in mysql. not date/Time.

0

In my data table there is a 0000-00-00 like this date inserted then I changed this date to correctly one like this 2020-01-28

Jalol
  • 23
  • 5