PC Review


Reply
Thread Tools Rate Thread

Assigning null value to DateTime

 
 
Bill Gower
Guest
Posts: n/a
 
      14th Feb 2007
How do I assign a null value to a datetime variable?

DateTime DateNonMember = DateTime.Parse("").ToString();

This doesn't work.

I also tried

DateTime DateNonMember = DBNull.Value


Bill


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      14th Feb 2007
Bill Gower <(E-Mail Removed)> wrote:
> How do I assign a null value to a datetime variable?


You can't. DateTime is a value type, like int, char and boolean.
(That's not an exhaustive list!)

If you're using .NET 2.0, you can use DateTime? which is a nullable
version of DateTime. See
http://pobox.com/~skeet/csharp/csharp2/nullable.html for more
information.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Tim Van Wassenhove
Guest
Posts: n/a
 
      14th Feb 2007
Bill Gower schreef:
> How do I assign a null value to a datetime variable?
> DateTime DateNonMember = DBNull.Value



DateTime is a value type so you can't assign null to it.
You can assign null to Nullable<DateTime> (DateTime? in c#)


--
Tim Van Wassenhove <url:http://www.timvw.be/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning a default value for DateTime in EntityFramework designer? Ralf Kaiser Microsoft ADO .NET 0 29th Sep 2008 01:55 PM
DateTime and NULL value =?Utf-8?B?RmlsaXAgRGUgQmFja2Vy?= Microsoft Dot NET Framework 1 21st May 2006 03:04 PM
DateTime null =?Utf-8?B?Sko=?= Microsoft C# .NET 7 12th May 2005 08:25 AM
Assigning a Null to Datetime Variable or Object =?Utf-8?B?U29sdXRpb24gU2Vla2Vy?= Microsoft VB .NET 2 12th Apr 2005 06:56 PM
Set DateTime value to null news.microsoft.com Microsoft ADO .NET 9 20th Jul 2004 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.