Why DateTime hasn't null value ? 
Author Message
 Why DateTime hasn't null value ?

Hi,

Why DateTime hasn't null value as SqlDateTime ?
(SqlDateTime.null)

It's hard to handle such situations where date isn't or mustn't specifed
(optional).



Sat, 28 May 2005 19:03:02 GMT  
 Why DateTime hasn't null value ?
DateTime is a struct, and structs cannot have null values. Set it to the
minimal datetime to signify a null value.


Quote:
> Hi,

> Why DateTime hasn't null value as SqlDateTime ?
> (SqlDateTime.null)

> It's hard to handle such situations where date isn't or mustn't specifed
> (optional).



Sat, 28 May 2005 22:10:00 GMT  
 Why DateTime hasn't null value ?
SqlDateTime is struct too.

Structs can't be set to reference null, following combination can be
implemented.
SqlDateTime dateTime = SqlDateTime.null;

Allows null values, but DateTime don't.


Quote:
> DateTime is a struct, and structs cannot have null values. Set it to the
> minimal datetime to signify a null value.



> > Hi,

> > Why DateTime hasn't null value as SqlDateTime ?
> > (SqlDateTime.null)

> > It's hard to handle such situations where date isn't or mustn't specifed
> > (optional).



Sat, 28 May 2005 22:21:57 GMT  
 Why DateTime hasn't null value ?
Notice, that you cannot say:
SqlDateTime dateTime = null;

SqlDateTime.null is a static member of the SqlDateTime datastructure! It is
not 'null' as it is used elsewhere, it is completely different.

So again, no value type (struct) can get a value of 'null'.


Quote:
> SqlDateTime is struct too.

> Structs can't be set to reference null, following combination can be
> implemented.
> SqlDateTime dateTime = SqlDateTime.null;

> Allows null values, but DateTime don't.



> > DateTime is a struct, and structs cannot have null values. Set it to the
> > minimal datetime to signify a null value.



> > > Hi,

> > > Why DateTime hasn't null value as SqlDateTime ?
> > > (SqlDateTime.null)

> > > It's hard to handle such situations where date isn't or mustn't
specifed
> > > (optional).



Sat, 28 May 2005 22:29:25 GMT  
 Why DateTime hasn't null value ?

Quote:
> Notice, that you cannot say:
> SqlDateTime dateTime = null;

I don't need to set reference to null.

I need following for DateTime

SqlDateTime dateTime = SqlDateTime.null;
if(dateTime == SqlDateTime.null){
    // Date value isn't specified

Quote:
}



Quote:
> Notice, that you cannot say:
> SqlDateTime dateTime = null;

> SqlDateTime.null is a static member of the SqlDateTime datastructure! It
is
> not 'null' as it is used elsewhere, it is completely different.

> So again, no value type (struct) can get a value of 'null'.



> > SqlDateTime is struct too.

> > Structs can't be set to reference null, following combination can be
> > implemented.
> > SqlDateTime dateTime = SqlDateTime.null;

> > Allows null values, but DateTime don't.



> > > DateTime is a struct, and structs cannot have null values. Set it to
the
> > > minimal datetime to signify a null value.



> > > > Hi,

> > > > Why DateTime hasn't null value as SqlDateTime ?
> > > > (SqlDateTime.null)

> > > > It's hard to handle such situations where date isn't or mustn't
> specifed
> > > > (optional).



Sat, 28 May 2005 22:41:00 GMT  
 Why DateTime hasn't null value ?
A DateTime cannot reference a SqlDateTime (which is what the Null property
is)! These are completely different structures and not related to each other
at all! You cannot do this!

Just use DateTime.MinValue to signify a missing date, and compare to that.


Quote:

> > Notice, that you cannot say:
> > SqlDateTime dateTime = null;
> I don't need to set reference to null.

> I need following for DateTime

> SqlDateTime dateTime = SqlDateTime.null;
> if(dateTime == SqlDateTime.null){
>     // Date value isn't specified
> }



> > Notice, that you cannot say:
> > SqlDateTime dateTime = null;

> > SqlDateTime.null is a static member of the SqlDateTime datastructure! It
> is
> > not 'null' as it is used elsewhere, it is completely different.

> > So again, no value type (struct) can get a value of 'null'.



> > > SqlDateTime is struct too.

> > > Structs can't be set to reference null, following combination can be
> > > implemented.
> > > SqlDateTime dateTime = SqlDateTime.null;

> > > Allows null values, but DateTime don't.



> > > > DateTime is a struct, and structs cannot have null values. Set it to
> the
> > > > minimal datetime to signify a null value.



> > > > > Hi,

> > > > > Why DateTime hasn't null value as SqlDateTime ?
> > > > > (SqlDateTime.null)

> > > > > It's hard to handle such situations where date isn't or mustn't
> > specifed
> > > > > (optional).



Sat, 28 May 2005 22:45:35 GMT  
 Why DateTime hasn't null value ?

Quote:

> > Notice, that you cannot say:
> > SqlDateTime dateTime = null;
> I don't need to set reference to null.

> I need following for DateTime

> SqlDateTime dateTime = SqlDateTime.null;
> if(dateTime == SqlDateTime.null){
>     // Date value isn't specified
> }

So decide on your own DateTime which is effectively "null", and use that
- just make sure you don't pick a value you might ever actually want to
use.

--

http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too



Sat, 28 May 2005 22:49:41 GMT  
 Why DateTime hasn't null value ?

Quote:
>These are completely different structures a

Probably you didn't read my previous messages completely ...


Quote:
> A DateTime cannot reference a SqlDateTime (which is what the Null property
> is)! These are completely different structures and not related to each
other
> at all! You cannot do this!

> Just use DateTime.MinValue to signify a missing date, and compare to that.



> > > Notice, that you cannot say:
> > > SqlDateTime dateTime = null;
> > I don't need to set reference to null.

> > I need following for DateTime

> > SqlDateTime dateTime = SqlDateTime.null;
> > if(dateTime == SqlDateTime.null){
> >     // Date value isn't specified
> > }



> > > Notice, that you cannot say:
> > > SqlDateTime dateTime = null;

> > > SqlDateTime.null is a static member of the SqlDateTime datastructure!
It
> > is
> > > not 'null' as it is used elsewhere, it is completely different.

> > > So again, no value type (struct) can get a value of 'null'.



> > > > SqlDateTime is struct too.

> > > > Structs can't be set to reference null, following combination can be
> > > > implemented.
> > > > SqlDateTime dateTime = SqlDateTime.null;

> > > > Allows null values, but DateTime don't.



> > > > > DateTime is a struct, and structs cannot have null values. Set it
to
> > the
> > > > > minimal datetime to signify a null value.



> > > > > > Hi,

> > > > > > Why DateTime hasn't null value as SqlDateTime ?
> > > > > > (SqlDateTime.null)

> > > > > > It's hard to handle such situations where date isn't or mustn't
> > > specifed
> > > > > > (optional).



Sat, 28 May 2005 22:50:31 GMT  
 Why DateTime hasn't null value ?
Ok, I think we got off topic after a while.

The reason it doesn't have a null, I imaging, is that in SqlDateTime, this
is meant to be a datatype in a database - which can have null values, so
they put in a constant for null there - null in database terms, not
programming. Since DateTime is not meant to be a database data type, it is
not there.


Quote:

> >These are completely different structures a
> Probably you didn't read my previous messages completely ...



> > A DateTime cannot reference a SqlDateTime (which is what the Null
property
> > is)! These are completely different structures and not related to each
> other
> > at all! You cannot do this!

> > Just use DateTime.MinValue to signify a missing date, and compare to
that.



> > > > Notice, that you cannot say:
> > > > SqlDateTime dateTime = null;
> > > I don't need to set reference to null.

> > > I need following for DateTime

> > > SqlDateTime dateTime = SqlDateTime.null;
> > > if(dateTime == SqlDateTime.null){
> > >     // Date value isn't specified
> > > }



> > > > Notice, that you cannot say:
> > > > SqlDateTime dateTime = null;

> > > > SqlDateTime.null is a static member of the SqlDateTime
datastructure!
> It
> > > is
> > > > not 'null' as it is used elsewhere, it is completely different.

> > > > So again, no value type (struct) can get a value of 'null'.



> > > > > SqlDateTime is struct too.

> > > > > Structs can't be set to reference null, following combination can
be
> > > > > implemented.
> > > > > SqlDateTime dateTime = SqlDateTime.null;

> > > > > Allows null values, but DateTime don't.



> > > > > > DateTime is a struct, and structs cannot have null values. Set
it
> to
> > > the
> > > > > > minimal datetime to signify a null value.



> > > > > > > Hi,

> > > > > > > Why DateTime hasn't null value as SqlDateTime ?
> > > > > > > (SqlDateTime.null)

> > > > > > > It's hard to handle such situations where date isn't or
mustn't
> > > > specifed
> > > > > > > (optional).



Sat, 28 May 2005 22:54:33 GMT  
 Why DateTime hasn't null value ?
hmm, null basically only has one meaning, although several nuances. "Not
Set", "Unknown" etc are versions of the theme.

What you need to be really clear about here is the difference between a null
reference and a null value.

.Net clearly supports null references;

Object myObj = null;

Here, I have a object reference, it really exists, and its value is null. I
don't know how .Net tracks this internally, but I suspect that it uses a
specially value, such as 0, to reflect a null (same method with pointers in
C++ - we can get away with that because 0 would never be valid user memory
address).

.Net doesn't support null values;

int i = null;        // Error!

In the case of an int, there just isn't anywhere to store its "null-ness",
and all its value range are useful ints too!

SQL does allow for null values. In the case of SQL Server, it does this by
having a bit array, one bit for each 'Allow Null' column, on every row.
Effectively, it has to supply some extra space to reflect where it is null
or not.

I guess the SQLDateTime struct also has a boolean to indicate that its null.

Finally, there is the problem that null values stuff up boolean logic.
Assuming null values were allowed:

int a = null;
int b = null;

then

(a == b)  returns null (not true).

In fact nearly any operation with null as an operand should return null! SQL
works like this, but most other language seem to get by with boolean logic.

Finally, it worth saying that a reference is really a value type, and in
.Net, its the only value type that supports a null value (and even then, not
properly, because comparisons with null return boolean). This is not a
criticism; this reflects the way most people want to handle nulls most of
the time.

--
Nick Holmes
Coyote Software, GmbH.


Quote:
> Ok, I think we got off topic after a while.

> The reason it doesn't have a null, I imaging, is that in SqlDateTime, this
> is meant to be a datatype in a database - which can have null values, so
> they put in a constant for null there - null in database terms, not
> programming. Since DateTime is not meant to be a database data type, it is
> not there.



> > >These are completely different structures a
> > Probably you didn't read my previous messages completely ...



> > > A DateTime cannot reference a SqlDateTime (which is what the Null
> property
> > > is)! These are completely different structures and not related to each
> > other
> > > at all! You cannot do this!

> > > Just use DateTime.MinValue to signify a missing date, and compare to
> that.



> > > > > Notice, that you cannot say:
> > > > > SqlDateTime dateTime = null;
> > > > I don't need to set reference to null.

> > > > I need following for DateTime

> > > > SqlDateTime dateTime = SqlDateTime.null;
> > > > if(dateTime == SqlDateTime.null){
> > > >     // Date value isn't specified
> > > > }



> > > > > Notice, that you cannot say:
> > > > > SqlDateTime dateTime = null;

> > > > > SqlDateTime.null is a static member of the SqlDateTime
> datastructure!
> > It
> > > > is
> > > > > not 'null' as it is used elsewhere, it is completely different.

> > > > > So again, no value type (struct) can get a value of 'null'.



> > > > > > SqlDateTime is struct too.

> > > > > > Structs can't be set to reference null, following combination ca
n
> be
> > > > > > implemented.
> > > > > > SqlDateTime dateTime = SqlDateTime.null;

> > > > > > Allows null values, but DateTime don't.



> > > > > > > DateTime is a struct, and structs cannot have null values. Set
> it
> > to
> > > > the
> > > > > > > minimal datetime to signify a null value.



> > > > > > > > Hi,

> > > > > > > > Why DateTime hasn't null value as SqlDateTime ?
> > > > > > > > (SqlDateTime.null)

> > > > > > > > It's hard to handle such situations where date isn't or
> mustn't
> > > > > specifed
> > > > > > > > (optional).



Sun, 29 May 2005 00:34:07 GMT  
 Why DateTime hasn't null value ?

Quote:
> hmm, null basically only has one meaning, although several nuances. "Not
> Set", "Unknown" etc are versions of the theme.

> What you need to be really clear about here is the difference between a
null
> reference and a null value.

> .Net clearly supports null references;

> Object myObj = null;

> Here, I have a object reference, it really exists, and its value is null.
I
> don't know how .Net tracks this internally, but I suspect that it uses a
> specially value, such as 0, to reflect a null (same method with pointers
in
> C++ - we can get away with that because 0 would never be valid user memory
> address).

> .Net doesn't support null values;

> int i = null;        // Error!

> In the case of an int, there just isn't anywhere to store its "null-ness",
> and all its value range are useful ints too!

> SQL does allow for null values. In the case of SQL Server, it does this by
> having a bit array, one bit for each 'Allow Null' column, on every row.
> Effectively, it has to supply some extra space to reflect where it is null
> or not.

> I guess the SQLDateTime struct also has a boolean to indicate that its

null.

Three options,

1. Why not use SqlDateTime yourself?  It supplies DateTime-->SqlDateTime and
SqlDateTime-->DateTime conversions.

2. SqlDateTime implements the INullable interface for its pattern (also
IComparable).  You may also do the same with your own custom structure, it
wouldn't be hard.

3. You could use either of these barebones wrapper classes.  Since it is a
class you can have null references to it and the wrapped DateTime structure
is freely visible whenever needed.  The second one gives the null-ness flag
in addition to the null reference ability.  Put getter and setters in there
to ease maintenance of the IsNull flag.

public class DateTime {
   public System.DateTime _dt;

Quote:
}

or

public class DateTime {
   public System.DateTime _dt;
   public bool _IsNull = true;

Quote:
}

-- Alan


Sun, 29 May 2005 00:55:25 GMT  
 Why DateTime hasn't null value ?


Quote:

> > Notice, that you cannot say:
> > SqlDateTime dateTime = null;
> I don't need to set reference to null.

> I need following for DateTime

> SqlDateTime dateTime = SqlDateTime.null;
> if(dateTime == SqlDateTime.null){
>     // Date value isn't specified
> }

Why don't you simply use SqlDateTime instead of DateTime?

   <- remainder of thread snipped ->
--
MikeB



Sun, 29 May 2005 04:17:31 GMT  
 Why DateTime hasn't null value ?

I want use usual types in WebServices, ... .


Quote:



> > > Notice, that you cannot say:
> > > SqlDateTime dateTime = null;
> > I don't need to set reference to null.

> > I need following for DateTime

> > SqlDateTime dateTime = SqlDateTime.null;
> > if(dateTime == SqlDateTime.null){
> >     // Date value isn't specified
> > }

> Why don't you simply use SqlDateTime instead of DateTime?

>    <- remainder of thread snipped ->
> --
> MikeB



Sun, 29 May 2005 15:28:14 GMT  
 Why DateTime hasn't null value ?
I think the standard way to represent a "null" or default
value for a DateTime is to use DateTime.MinValue.

-c


Quote:

> I want use usual types in WebServices, ... .





> > > > Notice, that you cannot say:
> > > > SqlDateTime dateTime = null;
> > > I don't need to set reference to null.

> > > I need following for DateTime

> > > SqlDateTime dateTime = SqlDateTime.null;
> > > if(dateTime == SqlDateTime.null){
> > >     // Date value isn't specified
> > > }

> > Why don't you simply use SqlDateTime instead of DateTime?

> >    <- remainder of thread snipped ->
> > --
> > MikeB



Mon, 30 May 2005 00:05:58 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. getting CSliderCtrl to notify even when value hasn't changed

2. null - value with DateTime

3. Null DateTime and Null int

4. NULL's value

5. NULL isn't 0/0 isn't NULL

6. Why doesn't SCANF add a NULL?

7. Global pointer is null sometimes even when initialized to some non-null value

8. VB has it, but VC hasn't

9. Using a define that hasn't been #defined

10. delete memory space that hasn't been allocated

11. How to detect that application looses focus / the user hasn't interacted for 5 minutes

12. why my dropdownlist doesn't return right value

 

 
Powered by phpBB® Forum Software