Hi,
Could you please let me know how to convert object type to DataTime type. You can refer the below code for more information
internal object Value
{
set
{
DateTime dt = Convert.ToDateTime(value);
this.SelectedDate = (dt == DateTime.MinValue)?null:dt.ToString("dd-MMM-yyyy");
}
}
value being passed to Value property is "19/12/2008 00:00:00".
Regards,
Atheeq
Fernando SotoPosted Dec 21, 2008, 1:59 PM
Here is a snippet on how it can be done.
// Set this to you culture. In this example it is set to Kannada (India)
// You can get the culture for your location from the CultureInfo class at
// http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx
CultureInfo culture = CultureInfo.CreateSpecificCulture("kn-IN");
DateTimeStyles styles = DateTimeStyles.None;
// Holds the converted value
String SelectedDate;
internal object Value
{
set
{
// Create a variable to hold the converted string value of the incomming data
DateTime dt;
// Convert the string in the object to a DateTime object if string can not be
// converted the value placed in dt will be DateTime.MinValue otherwise it will
// create a DateTime object with the valie being passed in.
DateTime.TryParse(value.ToString(), culture, styles, out dt);
// Set the value of SelectedDate
this.SelectedDate = (dt == DateTime.MinValue) ? null : dt.ToString("dd-MMM-yyyy");
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Value = "19/12/2008 00:00:00";
if( SelectedDate != null )
MessageBox.Show(SelectedDate.ToString());
}
Regards;
Fernando