Re: What changed with MySqlDbType.Datetime?
Posted by: Chris Cline
Date: November 18, 2004 02:43PM

Reggie,

Here is an alternative way of validating DateTime for the MySqlDateTime.Seralize()
This check the value in the even the time has been removed from the datetime which is a possiabilty if the user is working with a control that formats the DateTime to a ShortDate().

if (value is MySqlDateTime)
value = (value as MySqlDateTime).GetDateTime();
//
// if (! (value is DateTime))
// throw new MySqlException( "Only DateTime objects can be serialized by MySqlDateTime" );
DateTime dtValue;
try
{
System.Globalization.DateTimeFormatInfo mDate = new System.Globalization.DateTimeFormatInfo();
dtfi.ShortDatePattern = "M/d/yyyy";
dtValue = DateTime.ParseExact( value.ToString(), "d", mDate );
}
catch(Exception)
{
throw new MySqlException( "Only DateTime objects can be serialized by MySqlDateTime" );
}

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.