JoeBeez
JoeBeez

Reputation: 45

MySqlDateTime to System.DateTime conversion

Ok I'm very new to databases and C# in general, but I'm using a piece of code that exports dataset data to an Excel file, and its taking issue with the date/time format. I'm using the MySQL connector so the rowtype is MySql.Data.Types.MySqlDateTime. Is there any quick way to convert it into System.DateTime so I can slot it straight into the case statement?

Here's a link to the code I used, I copied it verbatim so I've not copied and pasted it here. It throws a MySql.Data.Types.MySqlDateTime not handled exception: Code Project Thanks in advance for any help.

Upvotes: 0

Views: 1955

Answers (2)

P Daddy
P Daddy

Reputation: 29527

Just call GetDateTime().

Upvotes: 3

Psytronic
Psytronic

Reputation: 6113

What I do, is to format the output in the query to the C# date time format, and parse the reults:

MySql Command

select DATE_FORMAT(NOW(), '%Y-%m-%d %T') as 'Date';

C#

DateTime x;
DateTime.tryParse(results["Date"], out x);

If you need more explanation just comment and ask :)

UPDATE FROM COMMENT Presuming that the appdate column is the date one:

SELECT appref, DATE_FORMAT(appdate, '%Y-%m-%d %T') as 'appdate'  FROM applications WHERE id > 810000

Upvotes: -1

Related Questions