943,879 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3367
  • C# RSS
Dec 21st, 2008
0

Convert Object type to DataTime?

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
na_atheeq is offline Offline
2 posts
since Dec 2008
Dec 21st, 2008
0

Re: Convert Object type to DataTime?

dateTime IS an object.
I'm not shure what you really asked, but I'm inferring you're referring to nullable types. Like this:
C# Syntax (Toggle Plain Text)
  1. DateTime? dt = new DateTime();
  2. dt = DateTime.Now;
  3. dt = null; //you can not do this if you don't use a ? in the declaration.
Last edited by ddanbe; Dec 21st, 2008 at 1:20 pm.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,740 posts
since Oct 2008
Dec 21st, 2008
0

Re: Convert Object type to DataTime?

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?"
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Cannot display custom icon in c# application
Next Thread in C# Forum Timeline: javascript in c#





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC