Date comparison

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig

    #1

    Date comparison

    Hello everyone,

    I've got a an issue with comparing dates in VB6 (sp4) and I would
    greatly appreciate help that anyone has to offer on this subject...
    :-)

    I have two variables (start_DateTime and end_DateTime). Both contain
    the following date information (this is what is printed in the
    'immediate' window when I execute the following code)...

    ?start_DateTime = 15/09/04 02:00:00
    ?end_DateTime = 15/09/04 02:00:00

    However, when I compare them both to see if there is a difference the
    following statement returns true(it thinks end_DateTime >
    start_DateTime) ...

    If (start_DateTime < end_DateTime) Then
    Do X
    Do Y
    Do Z
    End If

    However if I type the following...

    ?cdate("15/09/04 02:00:00") > cdate("15/09/04 02:00:00")

    It returns...
    False

    Why is this happening? I do not understand; I can only assume that
    there more information being held in the date data type than what I am
    seeing.

    Any help regarding this issue will be very much appreciated. Thank you
    in advance.

    SideNote:

    I'm not sure if this will help, but if I type

    ?end_DateTime - start_DateTime

    I get the following result...

    7.2759576141834 3E-12

    Regards,

    Craig.
  • J French

    #2
    Re: Date comparison

    On 14 Sep 2004 02:50:12 -0700, crgsmrt@hotmail .com (Craig) wrote:
    [color=blue]
    >Hello everyone,
    >
    >I've got a an issue with comparing dates in VB6 (sp4) and I would
    >greatly appreciate help that anyone has to offer on this subject...
    >:-)
    >
    >I have two variables (start_DateTime and end_DateTime). Both contain
    >the following date information (this is what is printed in the
    >'immediate' window when I execute the following code)...
    >
    >?start_DateTim e = 15/09/04 02:00:00
    >?end_DateTim e = 15/09/04 02:00:00
    >
    >However, when I compare them both to see if there is a difference the
    >following statement returns true(it thinks end_DateTime >
    >start_DateTime )...
    >
    >If (start_DateTime < end_DateTime) Then
    > Do X
    > Do Y
    > Do Z
    >End If
    >
    >However if I type the following...
    >
    >?cdate("15/09/04 02:00:00") > cdate("15/09/04 02:00:00")
    >
    >It returns...
    >False
    >
    >Why is this happening? I do not understand; I can only assume that
    >there more information being held in the date data type than what I am
    >seeing.[/color]

    Remember, that what you are printing is not exactly what is stored.

    Depending on where you are getting these DateTime variables, they
    could be different by a fraction of a second.

    A Date variable is really a Double

    Comment

    • Steve Gerrard

      #3
      Re: Date comparison


      "J French" <erewhon@nowher e.com> wrote in message
      news:4146d0d1.1 75278778@news.b tclick.com...
      | On 14 Sep 2004 02:50:12 -0700, crgsmrt@hotmail .com (Craig) wrote:
      |
      | >I have two variables (start_DateTime and end_DateTime). Both contain
      | >the following date information (this is what is printed in the
      | >'immediate' window when I execute the following code)...
      | >
      | >?start_DateTim e = 15/09/04 02:00:00
      | >?end_DateTim e = 15/09/04 02:00:00
      | >
      | >However, when I compare them both to see if there is a difference the
      | >following statement returns true(it thinks end_DateTime >
      | >start_DateTime )...
      | >
      ||
      | Remember, that what you are printing is not exactly what is stored.
      |
      | Depending on where you are getting these DateTime variables, they
      | could be different by a fraction of a second.
      |
      | A Date variable is really a Double

      Exactly. Try this in the immediate window:
      ?CDbl(start_Dat eTime)
      ?CDbl(end_DateT ime)

      and also
      ?end_DateTime - start_DateTime


      Comment

      • DavidB

        #4
        Re: Date comparison

        Craig, what are you trying to accomplish with the Date code?

        As the others said, the code is not lying; the enddate is greater, by the
        difference you came up with, then the startdate, but depending upon what you
        are trying to accomplish, there are various ways to compensate for the
        results.

        "Craig" <crgsmrt@hotmai l.com> wrote in message
        news:48c681cb.0 409140150.a600c 63@posting.goog le.com...[color=blue]
        > Hello everyone,
        >
        > I've got a an issue with comparing dates in VB6 (sp4) and I would
        > greatly appreciate help that anyone has to offer on this subject...
        > :-)
        >
        > I have two variables (start_DateTime and end_DateTime). Both contain
        > the following date information (this is what is printed in the
        > 'immediate' window when I execute the following code)...
        >
        > ?start_DateTime = 15/09/04 02:00:00
        > ?end_DateTime = 15/09/04 02:00:00
        >
        > However, when I compare them both to see if there is a difference the
        > following statement returns true(it thinks end_DateTime >
        > start_DateTime) ...
        >
        > If (start_DateTime < end_DateTime) Then
        > Do X
        > Do Y
        > Do Z
        > End If
        >
        > However if I type the following...
        >
        > ?cdate("15/09/04 02:00:00") > cdate("15/09/04 02:00:00")
        >
        > It returns...
        > False
        >
        > Why is this happening? I do not understand; I can only assume that
        > there more information being held in the date data type than what I am
        > seeing.
        >
        > Any help regarding this issue will be very much appreciated. Thank you
        > in advance.
        >
        > SideNote:
        >
        > I'm not sure if this will help, but if I type
        >
        > ?end_DateTime - start_DateTime
        >
        > I get the following result...
        >
        > 7.2759576141834 3E-12
        >
        > Regards,
        >
        > Craig.[/color]


        Comment

        Working...