473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

null date?

why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)
Nov 15 '05 #1
6 10061
Hi,

The DateTime data type is a value type and not reference
type.

For more information about value types and reference
types, look at these url's

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/csref/html/vcrefvaluetypes.asp

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/csref/html/vcrefvaluetypes.asp

The bottom line is, the value type cannot hold null
values unlike reference types.

So the work arounds which i can think of is to,

1) Assign a date like 1/1/1900 which will be considered
as null.
2) Create a class which has a field of type date. This
can be done in a smart way, such that you use it like a
normal value type, i.e., you don't need to use 'new' to
create the instance of the class.
This can be acheived by using implicit operator.
Thus, you get the ease of use of value type and also for
types like date you can assign null value since the class
is a reference type.

Hope this helps!!

Regards,
Madhu

MVP | MCSD.NET
-----Original Message-----
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date untilan event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = nullproperty

is there any way around this?
--
#-)
.

Nov 15 '05 #2
Hiya,

This is a common challenge for developers with with the split
reference/value type system. Many developers go for a magic date which
"means" null but it is far from ideal. You may like to look at the
NullableTypes project being hosted at SourceForge. It provides wrapper
classes around the standard structs which are nullable. You will probably
want to see what impact these have on performance in your application - the
license terms seem to be OK.

----------------------------------------
- Mitch Denny
- mi*********@monash.net
- http://www.monash.net
- +61 (414) 610141
-

"evolve" <NOngnSPAMpeaSPAMrseNO_S__PAMhotmail.com> wrote in message
news:uX****************@TK2MSFTNGP09.phx.gbl...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #3
You could use System.Data.SqlTypes.SqlDate
"evolve" <NOngnSPAMpeaSPAMrseNO_S__PAMhotmail.com> wrote in message
news:uX****************@TK2MSFTNGP09.phx.gbl...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #4
Use the static property DateTime.MinValue. (which is 01/01/0001 12:00AM)

This is considered to be a null date.

HTH
Brian w

"evolve" <NOngnSPAMpeaSPAMrseNO_S__PAMhotmail.com> wrote in message
news:uX****************@TK2MSFTNGP09.phx.gbl...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until
an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null
property

is there any way around this?
--
#-)

Nov 15 '05 #5
There is one caveat to using DateTime.MinValue... the actual date
(01/01/0001) is not supported by most database vendors. For example, I
believe that SQL Server throws an exception for dates less than 1/1/1900.
You can write code to get around this by translating the DateTime.MinValue
to a DbNull value before writing it to the database but this is a little
troublesome unless you have a good framework setup. For an enterprise
application, you wouldn't want to rely on individual programmers to
constantly be checking against the DateTime.MinValue every time a database
access occurs. As some of the other responses pointed out, a wrapper class
is a good way to avoid some of these issues.

Hopes this helps....

"Brian W" <brianw@gold_death_2_spam_rush.com> wrote in message
news:Oe*************@TK2MSFTNGP10.phx.gbl...
Use the static property DateTime.MinValue. (which is 01/01/0001 12:00AM)

This is considered to be a null date.

HTH
Brian w

"evolve" <NOngnSPAMpeaSPAMrseNO_S__PAMhotmail.com> wrote in message
news:uX****************@TK2MSFTNGP09.phx.gbl...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null property

is there any way around this?
--
#-)


Nov 15 '05 #6
Ed
Which is great, but they don't serialize...
-----Original Message-----
You could use System.Data.SqlTypes.SqlDate
"evolve" <NOngnSPAMpeaSPAMrseNO_S__PAMhotmail.com> wrote in messagenews:uX****************@TK2MSFTNGP09.phx.gbl...
why doesn't c# seem to support some kind of 'null date'

for instance:

i have an application where the user is not obliged to enter a date until an event happens (e.g. a bug was fixed on xyz)

the calendar control in asp.net doesn't seem to have a selectedDate = null property

is there any way around this?
--
#-)

.

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kris M | last post by:
How do i handle a null value for a date variable type. I am retrieving date data from an access database and storing the records in an array for processing. The array field has a date type and the...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
5
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
9
by: John Sidney-Woollett | last post by:
Hi I'm building a web app where changes to customer orders are logged in the following table, and I worried about the time that it will take to locate records that need further...
6
by: recif20002002 | last post by:
Hello I am trying to update table1 and set a new value with a condition selecting only the results for the element with the specified ID and the first one with the Date field null. The query...
5
by: Amogh | last post by:
Hi, My question is related to setting freed pointers to NULL. After freeing a pointer: 1) Should the freeing routine also be responsible for setting the pointer to null? 2) Or, should the...
5
by: AAJ | last post by:
Hi Does anyone know of any good publically available set of standards for managing dates when dealing with a database server (in my case SQL Server 2000 and c# VS2005). At the moment, if I...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
3
by: cmartin1986 | last post by:
I have written a sql query and I need it to return 0 when it doesn't find any matches to my criteria. I have tried adding iif statements, tried sum, and just Count, all of these methods work fine to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.