|
-
Dec 2nd, 2008, 09:56 AM
#1
Thread Starter
Fanatic Member
VB.Net Date.MinValue
In a Database Aplication I need to check if Periodes overlap but I need to diffrentiate between startdates that aren't filled and startdates In an infinate Past
So how do I workaround this problem...
using a nullable(of Date) gives hell as well because a date can contain nothing as well as a minvalue and in some cases it will give a
.hasvalue = False
but in other situtions a .hasvalue = True with a date of Date.Minvalue!
'Just a startdate
Dim StartDate as Date
' code somewhere in the user interface to indicate an infinate startdate
StartDate = Date.Minvalue
' Somewhere in validation of Data before storing in the database
If StratDate is nothing then
'This mesage will appear!!!!!!!
Msgbox("You need to enter a startdate")
end if
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 3rd, 2008, 06:34 AM
#2
Thread Starter
Fanatic Member
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 8th, 2008, 08:19 AM
#3
Thread Starter
Fanatic Member
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 8th, 2008, 08:45 AM
#4
Re: VB.Net Date.MinValue
I read this thread a while ago and I really don't know what you're saying. It would appear that nobody else does either. If you're using Date.MinValue to indicate "null" dates then test for Date.MinValue. What's the problem?
vb.net Code:
If Not myNullableDate.HasValue OrElse myNullableDate.Value = Date.MinValue Then 'No date. End If
-
Dec 9th, 2008, 07:10 AM
#5
Thread Starter
Fanatic Member
Re: VB.Net Date.MinValue
The problem is, I want to be able to distinquish between Date.MinValue and nothing.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 9th, 2008, 08:09 AM
#6
Re: VB.Net Date.MinValue
 Originally Posted by Dnereb
The problem is, I want to be able to distinquish between Date.MinValue and nothing.
The simple fact is that you can't if you use a Date and you can if you use a Nullable(Of Date). Use the types how they're supposed to be used and you'll get the behaviour you want. Don't use them the way they're intended and you won't. You can't expect magic.
-
Dec 9th, 2008, 08:39 AM
#7
Thread Starter
Fanatic Member
Re: VB.Net Date.MinValue
Well to be honest I think it's a breach of concept that's the problem.
Integer.minValue isn't nothing
Double.minValue isn't nothing
and so on...
but
Date.minvalue equals nothing! weird... at least
the problem starts when I get a data from a user input from using a DatetimeInput
The bound Nullable (of Date) (to a businessObject, not a dataset) will return a
.Hasvalue = True and a value of Nothing or Date.Minvalue if a user deleted a date.
Although it should be
.hasvalue = False
The problem arrises comparing periods I need to compare periods starting infinate in the past against other periods, but not periods without any UserInput
I'm afraid I've lost you again in this explanation, but anyways Thx for the afford anyways.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 9th, 2008, 08:56 AM
#8
Re: VB.Net Date.MinValue
 Originally Posted by Dnereb
Well to be honest I think it's a breach of concept that's the problem.
Integer.minValue isn't nothing
Double.minValue isn't nothing
and so on...
but
Date.minvalue equals nothing! weird... at least
Nothing weird about it. Nothing as an Integer is simply zero. Are you telling me that's not intuitive? What's the Date equivalent of zero? Could it be 01/01/0001 12:00:00 AM? Is that not the most intuitive choice?
 Originally Posted by Dnereb
the problem starts when I get a data from a user input from using a DatetimeInput
The bound Nullable (of Date) (to a businessObject, not a dataset) will return a
.Hasvalue = True and a value of Nothing or Date.Minvalue if a user deleted a date.
Although it should be
.hasvalue = False
The problem arrises comparing periods I need to compare periods starting infinate in the past against other periods, but not periods without any UserInput
I'm afraid I've lost you again in this explanation, but anyways Thx for the afford anyways.
What's a DatetimeInput? Are you talking about a DateTimePicker? Microsoft have never claimed that the DateTimePicker will bind to null Date values. Just don't use data binding in this case and if you want to be able to represent a null value then set ShowCheckBox to True:
vb.net Code:
Dim myDate As Date? = If(myDateTimePicker.Checked, myDateTimePicker.Value, Nothing)
-
Dec 14th, 2008, 05:39 AM
#9
Thread Starter
Fanatic Member
Re: VB.Net Date.MinValue
 Originally Posted by jmcilhinney
Nothing weird about it. Nothing as an Integer is simply zero.
An integer can't be nothing and has a default value of zero... that's not the same.
Code:
Dim I as integer
I = Nothing
If I = Nothing then
Will give syntax errors on the second and third line... but
Code:
Dim D as Date
D = Nothing
If D = nothing then
Won't give an error... the Minvalue equals Nothing that is very inconsistent with the object oriented concept of Nothing means there's no object at all.
I'm using a Devcomponents Dotnetbar control in this case, it can bind to an nullable of date but it encounters the same problem as I do in the code behind.
And I don't wan't a 'zero' value of 01-01-0001 to be shown in a inputfield for
the date someone has passed away if he or she is still alive.
But I've learned to live with writing ugly code for date input by now.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Dec 14th, 2008, 06:56 AM
#10
Re: VB.Net Date.MinValue
 Originally Posted by Dnereb
An integer can't be nothing and has a default value of zero... that's not the same.
Code:
Dim I as integer
I = Nothing
If I = Nothing then
Will give syntax errors on the second and third line... but
Code:
Dim D as Date
D = Nothing
If D = nothing then
Won't give an error...
Um, maybe you should have tested that before you posted it. That first code snippet is perfectly legal and will cause no errors. I'm afraid you don't understand exactly what Nothing is. As you say, an Integer can't actually be nothing in the sense of being no object. Nor can a Date, a Boolean or any other value type, so obviously Nothing does NOT mean no object. Let's ask MSDN what Nothing means:
Represents the default value of any data type.
What Nothing literally does is set each bit in a stack variable to zero. How exactly that zero value is interpreted depends on the type of the variable. If it's ANY reference type then it's interpreted as no object. If it's a value type then it's interpreted as the default value for that type. The default value for the Integer type is 0. The default value for all numeric types is zero, in their own flavour: 0 for Integer, 0L for Long, 0D for decimal, 0.0 for Double, etc. The default value for Boolean is False. The default value for Date is #1/01/0001#.
You're trying to show that there's an inconsistency where there is none because you're trying to show that there's some relationship between the MinValue field of various types and the default values of those types. There is no such relationship. Each value type has a default value defined. Some value types have a MinValue field. Microsoft never said, either explicitly or implicitly, that there was any connection between the value of those MinValue fields and the types' default values. The fact that some are the same is of no significance whatsoever, so the fact that some are not is not inconsistent because there is no trend to be consistent with.
-
Dec 14th, 2008, 07:55 AM
#11
Thread Starter
Fanatic Member
Re: VB.Net Date.MinValue
Hmmm,
I have to eat my shoe now...
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|