| | |
Convert Object type to DataTime?
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
dateTime IS an object.
I'm not shure what you really asked, but I'm inferring you're referring to nullable types. Like this:
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)
DateTime? dt = new DateTime(); dt = DateTime.Now; 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
Make love, no war. Cave ab homine unius libri.
Danny
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Other Threads in the C# Forum
- Previous Thread: Cannot display custom icon in c# application
- Next Thread: javascript in c#
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation event excel file form format formatting forms function gdi+ httpwebrequest image index input install interface java label list listbox mandelbrot math mouse mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remote remoting resource restore richtextbox server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml






