| | |
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 |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






