Convert MySQL DATETIME to System.DateTime
Well, if you have a result set containing MySql values DateTime
, you can use the method ConvertAll
along with a delegate DateTime.Parse
to create a collection of the System.DateTime
value.
Here is an example where "results" are the result of your dblinq query containing MySQL datetime values:
List<DateTime> dateTimes = results.ConvertAll(delegate(string time){
return DateTime.Parse(time);
});
Is this what you are looking for?
source to share
I was moving a column in my gridview from asp: BoundField to asp: TemplateField so it had to explicitly set the date from MySQL database. I found through reflection that the collection typed the date fields as MySqlDateTime and not system.DateTime.
I added the import operation MySql.Data.Types to the code behind and the following Eval statement on the label in the gridview context.
Text = '<% # CType (Eval ("Submitted_Date"), MySql.Data.Types.MySqlDateTime) .ToString%>'
output format: 02/23/2011
Hope it helps!
source to share