开发者

MySqlDateTime to System.DateTime conversion

Ok I'm ver开发者_运维知识库y 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.


Just call GetDateTime().


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜