Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I tried the following to null the default date, but no result. What is wrong in it.

if (exg.CertficateDatetime == ("01/01/1753"))
{
(exg.CertficateDatetime) = null;
}

Thanks in advance.
Posted
Comments
Prasad Avunoori 4-Jul-14 0:55am    
What is the datatype of CertficateDatetime?
Murugan.NM 4-Jul-14 1:00am    
Date
PrakashCs.net 4-Jul-14 1:06am    
yes use DateTime? MyDate=null; correct answer Suvabrata Roy

Hi,


DateTime is a value type so if you want to set null value in datetime filed it throw error.

there are some work around that's is :

C#
DateTime? MyDate=null;

Or
C#
Nullable<datetime> MyDate=null;</datetime>


They are same as per CLR.
 
Share this answer
 
The type System.DateTime is not a reference type but is a value type:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

To have a nullable type, use the type System.DateTime?:
C#
System.DateTime? referenceTime = null;

//...

referenceTime = System.DateTime.Now; // not null

SystemDateTime valueTime = time.Value; // assignment between objects of value and reference types


Please see:
http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/2cf62fcy%28v=vs.120%29.aspx[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900