Results 1 to 11 of 11

Thread: VB.Net Date.MinValue

  1. #1

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    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.

  2. #2

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: VB.Net Date.MinValue

    Ping...
    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.

  3. #3

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: VB.Net Date.MinValue

    ping, ping...
    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. If Not myNullableDate.HasValue OrElse myNullableDate.Value = Date.MinValue Then
    2.     'No date.
    3. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.Net Date.MinValue

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    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.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.Net Date.MinValue

    Quote 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?
    Quote 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:
    1. Dim myDate As Date? = If(myDateTimePicker.Checked, myDateTimePicker.Value, Nothing)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: VB.Net Date.MinValue

    Quote 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.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.Net Date.MinValue

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    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
  •  



Click Here to Expand Forum to Full Width