Hi,

Could you please let me know how to convert object type to DataTime. 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

Recommended Answers

All 2 Replies

dateTime IS an object.
I'm not shure what you really asked, but I'm inferring you're referring to nullable types. Like this:

DateTime? dt = new DateTime();
            dt = DateTime.Now;
            dt = null; //you can not do this if you don't use a ? in the declaration.

To explain DDanbe answer, DateTime is value type which means can't be null to make it accepts null you should add nullable flavor "DateTime?"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.