Convert Object type to DataTime?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 2
Reputation: na_atheeq is an unknown quantity at this point 
Solved Threads: 0
na_atheeq na_atheeq is offline Offline
Newbie Poster

Convert Object type to DataTime?

 
0
  #1
Dec 21st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,943
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 279
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Convert Object type to DataTime?

 
0
  #2
Dec 21st, 2008
dateTime IS an object.
I'm not shure what you really asked, but I'm inferring you're referring to nullable types. Like this:
  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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Convert Object type to DataTime?

 
0
  #3
Dec 21st, 2008
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?"
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC