Date Comparison

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kurien Baker Fenn

    #1

    Date Comparison

    I have a problem in comparing two dates.when i compare two dates it's only
    taking the days into consideration.f or example when i select 10th may 2004 as
    my first date and 1st may 2004 as my second date,it will say that 10th may is
    greater.what might be the problem.please help me
    Thanks in advance.
  • Nick Malik

    #2
    Re: Date Comparison

    please put up a small snippet of code that illustrates the actual problem
    you are having and describe the behavior that you are expecting.

    Your message appears to demonstrate expected behavior. (May 10th, '04 is
    greater than May 1st, '04)

    --- Nick

    "Kurien Baker Fenn" <KurienBakerFen n@discussions.m icrosoft.com> wrote in
    message news:B5946C6A-520C-4D57-AA3D-CE85F8D55806@mi crosoft.com...[color=blue]
    > I have a problem in comparing two dates.when i compare two dates it's only
    > taking the days into consideration.f or example when i select 10th may 2004[/color]
    as[color=blue]
    > my first date and 1st may 2004 as my second date,it will say that 10th may[/color]
    is[color=blue]
    > greater.what might be the problem.please help me
    > Thanks in advance.[/color]


    Comment

    • Cor Ligthert

      #3
      Re: Date Comparison

      Kurien,

      Basicly it is the best to compare dates in the datetime format that goes
      right in all culturesettings in the world
      VB code
      \\\
      dim a as datetime = new datetime(2004,5 ,10)
      dim b as datetime = new datetime(2004,5 ,10
      if a > b etc.
      ///

      I hope this helps?

      Cor


      Comment

      • Nick Malik

        #4
        Re: Date Comparison

        I've been following the conversation. Looks like Cor may have hit on the
        problem. I'd like to add a little to his excellent response.

        Kurien,
        We assume that you are first declaring your variables:
        Dim CalendarDate1, CalendarDate2

        You should first change these statements to:
        Dim CalendarDate1 as DateTime
        Dim CalendarDate2 as DateTime

        Secondly, you should not convert the values to string before comparing them:

        Private Sub Calendar1_Click ()
        CalendarDate1 = Calendar1.Value '<-- notice the change here
        Command1.Enable d = False
        MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here
        End Sub


        Hope this helps,
        --- Nick


        "Kurien Baker Fenn" <KurienBakerFen n@discussions.m icrosoft.com> wrote in
        message news:B5946C6A-520C-4D57-AA3D-CE85F8D55806@mi crosoft.com...[color=blue]
        > I have a problem in comparing two dates.when i compare two dates it's only
        > taking the days into consideration.f or example when i select 10th may 2004[/color]
        as[color=blue]
        > my first date and 1st may 2004 as my second date,it will say that 10th may[/color]
        is[color=blue]
        > greater.what might be the problem.please help me
        > Thanks in advance.[/color]


        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: Date Comparison

          Nick,
          One minor correction:[color=blue]
          > MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here[/color]

          MsgBox CalendarDate1.T oString("dd-MM-yyyy") '<-- notice the change
          here

          Otherwise I concur with you & Cor.

          Hope this helps
          Jay

          "Nick Malik" <nickmalik@hotm ail.nospam.com> wrote in message
          news:egT8d.1975 18$D%.164272@at tbi_s51...[color=blue]
          > I've been following the conversation. Looks like Cor may have hit on the
          > problem. I'd like to add a little to his excellent response.
          >
          > Kurien,
          > We assume that you are first declaring your variables:
          > Dim CalendarDate1, CalendarDate2
          >
          > You should first change these statements to:
          > Dim CalendarDate1 as DateTime
          > Dim CalendarDate2 as DateTime
          >
          > Secondly, you should not convert the values to string before comparing
          > them:
          >
          > Private Sub Calendar1_Click ()
          > CalendarDate1 = Calendar1.Value '<-- notice the change here
          > Command1.Enable d = False
          > MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here
          > End Sub
          >
          >
          > Hope this helps,
          > --- Nick
          >
          >
          > "Kurien Baker Fenn" <KurienBakerFen n@discussions.m icrosoft.com> wrote in
          > message news:B5946C6A-520C-4D57-AA3D-CE85F8D55806@mi crosoft.com...[color=green]
          >> I have a problem in comparing two dates.when i compare two dates it's
          >> only
          >> taking the days into consideration.f or example when i select 10th may
          >> 2004[/color]
          > as[color=green]
          >> my first date and 1st may 2004 as my second date,it will say that 10th
          >> may[/color]
          > is[color=green]
          >> greater.what might be the problem.please help me
          >> Thanks in advance.[/color]
          >
          >[/color]


          Comment

          • Nick Malik

            #6
            Re: Date Comparison

            I've been following the conversation. Looks like Cor may have hit on the
            problem. I'd like to add a little to his excellent response.

            Kurien,
            We assume that you are first declaring your variables:
            Dim CalendarDate1, CalendarDate2

            You should first change these statements to:
            Dim CalendarDate1 as DateTime
            Dim CalendarDate2 as DateTime

            Secondly, you should not convert the values to string before comparing them:

            Private Sub Calendar1_Click ()
            CalendarDate1 = Calendar1.Value '<-- notice the change here
            Command1.Enable d = False
            MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here
            End Sub


            Hope this helps,
            --- Nick


            "Kurien Baker Fenn" <KurienBakerFen n@discussions.m icrosoft.com> wrote in
            message news:B5946C6A-520C-4D57-AA3D-CE85F8D55806@mi crosoft.com...[color=blue]
            > I have a problem in comparing two dates.when i compare two dates it's only
            > taking the days into consideration.f or example when i select 10th may 2004[/color]
            as[color=blue]
            > my first date and 1st may 2004 as my second date,it will say that 10th may[/color]
            is[color=blue]
            > greater.what might be the problem.please help me
            > Thanks in advance.[/color]


            Comment

            • Jay B. Harlow [MVP - Outlook]

              #7
              Re: Date Comparison

              Nick,
              One minor correction:[color=blue]
              > MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here[/color]

              MsgBox CalendarDate1.T oString("dd-MM-yyyy") '<-- notice the change
              here

              Otherwise I concur with you & Cor.

              Hope this helps
              Jay

              "Nick Malik" <nickmalik@hotm ail.nospam.com> wrote in message
              news:egT8d.1975 18$D%.164272@at tbi_s51...[color=blue]
              > I've been following the conversation. Looks like Cor may have hit on the
              > problem. I'd like to add a little to his excellent response.
              >
              > Kurien,
              > We assume that you are first declaring your variables:
              > Dim CalendarDate1, CalendarDate2
              >
              > You should first change these statements to:
              > Dim CalendarDate1 as DateTime
              > Dim CalendarDate2 as DateTime
              >
              > Secondly, you should not convert the values to string before comparing
              > them:
              >
              > Private Sub Calendar1_Click ()
              > CalendarDate1 = Calendar1.Value '<-- notice the change here
              > Command1.Enable d = False
              > MsgBox CalendarDate1.F ormat("dd-MM-yyyy") '<-- notice the change here
              > End Sub
              >
              >
              > Hope this helps,
              > --- Nick
              >
              >
              > "Kurien Baker Fenn" <KurienBakerFen n@discussions.m icrosoft.com> wrote in
              > message news:B5946C6A-520C-4D57-AA3D-CE85F8D55806@mi crosoft.com...[color=green]
              >> I have a problem in comparing two dates.when i compare two dates it's
              >> only
              >> taking the days into consideration.f or example when i select 10th may
              >> 2004[/color]
              > as[color=green]
              >> my first date and 1st may 2004 as my second date,it will say that 10th
              >> may[/color]
              > is[color=green]
              >> greater.what might be the problem.please help me
              >> Thanks in advance.[/color]
              >
              >[/color]


              Comment

              • Cor Ligthert

                #8
                Re: Date Comparison

                Doh stupid me I was just changing text typed it and using Cstr, which I
                normally never use.
                [color=blue]
                > Otherwise I concur with you & Cor.[/color]

                me too Jay, I corrected it at the original message.

                nock nock nock nock on my head

                thanks,

                Cor




                Comment

                • Cor Ligthert

                  #9
                  Re: Date Comparison

                  Doh stupid me I was just changing text typed it and using Cstr, which I
                  normally never use.
                  [color=blue]
                  > Otherwise I concur with you & Cor.[/color]

                  me too Jay, I corrected it at the original message.

                  nock nock nock nock on my head

                  thanks,

                  Cor




                  Comment

                  Working...