ASP DateDiff

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

    ASP DateDiff

    I face that problems

    07/01/2003 06/30/2006 ---------> it should be 3



    01/01/2003 02/28/2005 --------->could i get 2 years and 2 months


    01/01/2003 03/01/2005 --------->could i get 2 years and 2 months and 1
    day



  • Bob Barrows [MVP]

    #2
    Re: ASP DateDiff

    inamori wrote:[color=blue]
    > I face that problems
    >
    > 07/01/2003 06/30/2006 ---------> it should be 3
    >
    >
    >
    > 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months
    >
    >
    > 01/01/2003 03/01/2005 --------->could i get 2 years and 2 months
    > and 1 day[/color]

    Could you explain why these aren't the correct results?

    The difference between 7/1/2003 and 6/30/2006 is:
    3 years, 11 months, and 29 days
    The difference between 1/1/2003 and 2/28/2005 is:
    2 years, 1 months, and 27 days
    The difference between 1/1/2003 and 3/1/2005 is:
    2 years, 2 months, and 0 days

    What is the logic used to determine when to add one day to the results?
    Should the difference between 07/01/2003 and 07/01/2003 be 1 day? How about
    07/01 and 07/02?

    This is the code I used to get the above results:
    <%
    dim arDates(2,1), iYrs, iMths, iDays, i
    arDates(0,0) = #2003-07-01#
    arDates(0,1) = #2006-06-30#
    arDates(1,0) = #2003-01-01#
    arDates(1,1) = #2005-02-28#
    arDates(2,0) = #2003-01-01#
    arDates(2,1) = #2005-03-01#

    for i = 0 to 2
    Response.Write "The difference between " & arDates(i,0) & _
    " and " & arDates(i,1) & " is: "
    iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
    Response.Write iYrs & " years, "
    iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
    if iMths < 12*iYrs then iYrs = iYrs - 1
    if iMths - 12*iYrs < 0 then
    Response.Write " 0 months, and "
    else
    Response.Write iMths - 12*iYrs & " months, and "
    end if
    iDays = DateDiff("d",ar Dates(i,0), _
    DateAdd("m", -1*iMths, arDates(i,1)))
    if iDays < 1 then iDays = 0
    Response.Write iDays & " days"
    Response.Write "<BR>"
    next
    %>

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Comment

    • Evertjan.

      #3
      Re: ASP DateDiff

      Bob Barrows [MVP] wrote on 21 aug 2004 in
      microsoft.publi c.inetserver.as p.general:[color=blue]
      > Could you explain why these aren't the correct results?
      >
      > The difference between 7/1/2003 and 6/30/2006 is:
      > 3 years, 11 months, and 29 days[/color]

      Hi, Bob,

      2000 years ago, people where used to including the first and last day in a
      declaration of time passed.

      It was like a 100 meter long barbed wire fence, with one pole per meter
      consisting of 101 poles.

      Likewise a duration of 7 weeks, 49 days in modern count, was called 50
      days, pentecost [whitsun, 49 days after easter] being the Greek word
      pentakosta for 50.

      I suppose the OQ could be of ancient stock.


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • inamori

        #4
        Re: ASP DateDiff

        Thanks for yoiur programming

        add one day because of business logic

        Lease agreement

        01/01/2003 12/31/2006 3 years

        01/01/2003 01/01/2007 3 years + 1 day

        That why i need add one day on the end date....


        "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
        news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...[color=blue]
        > inamori wrote:[color=green]
        > > I face that problems
        > >
        > > 07/01/2003 06/30/2006 ---------> it should be 3
        > >
        > >
        > >
        > > 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months
        > >
        > >
        > > 01/01/2003 03/01/2005 --------->could i get 2 years and 2 months
        > > and 1 day[/color]
        >
        > Could you explain why these aren't the correct results?
        >
        > The difference between 7/1/2003 and 6/30/2006 is:
        > 3 years, 11 months, and 29 days
        > The difference between 1/1/2003 and 2/28/2005 is:
        > 2 years, 1 months, and 27 days
        > The difference between 1/1/2003 and 3/1/2005 is:
        > 2 years, 2 months, and 0 days
        >
        > What is the logic used to determine when to add one day to the results?
        > Should the difference between 07/01/2003 and 07/01/2003 be 1 day? How[/color]
        about[color=blue]
        > 07/01 and 07/02?
        >
        > This is the code I used to get the above results:
        > <%
        > dim arDates(2,1), iYrs, iMths, iDays, i
        > arDates(0,0) = #2003-07-01#
        > arDates(0,1) = #2006-06-30#
        > arDates(1,0) = #2003-01-01#
        > arDates(1,1) = #2005-02-28#
        > arDates(2,0) = #2003-01-01#
        > arDates(2,1) = #2005-03-01#
        >
        > for i = 0 to 2
        > Response.Write "The difference between " & arDates(i,0) & _
        > " and " & arDates(i,1) & " is: "
        > iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
        > Response.Write iYrs & " years, "
        > iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
        > if iMths < 12*iYrs then iYrs = iYrs - 1
        > if iMths - 12*iYrs < 0 then
        > Response.Write " 0 months, and "
        > else
        > Response.Write iMths - 12*iYrs & " months, and "
        > end if
        > iDays = DateDiff("d",ar Dates(i,0), _
        > DateAdd("m", -1*iMths, arDates(i,1)))
        > if iDays < 1 then iDays = 0
        > Response.Write iDays & " days"
        > Response.Write "<BR>"
        > next
        > %>
        >
        > Bob Barrows
        > --
        > Microsoft MVP - ASP/ASP.NET
        > Please reply to the newsgroup. This email account is my spam trap so I
        > don't check it very often. If you must reply off-line, then remove the
        > "NO SPAM"
        >
        >[/color]


        Comment

        • Bob Barrows [MVP]

          #5
          Re: ASP DateDiff

          Change the code to this:

          <%
          dim arDates(2,1), iYrs, iMths, iDays, i, dDate
          arDates(0,0) = #2003-07-01#
          arDates(0,1) = #2006-06-30#
          arDates(1,0) = #2003-01-01#
          arDates(1,1) = #2005-02-28#
          arDates(2,0) = #2003-01-01#
          arDates(2,1) = #2005-03-01#

          for i = 0 to 2
          dDate = DateAdd("d",1,a rDates(i,1))
          Response.Write "The difference between " & arDates(i,0) & _
          " and " & dDate & " is: "
          iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
          Response.Write iYrs & " years, "
          iMths=DateDiff( "m",arDates(i,0 ),dDate)
          if iMths < 12*iYrs then iYrs = iYrs - 1
          if iMths - 12*iYrs < 0 then
          Response.Write " 0 months, and "
          else
          Response.Write iMths - 12*iYrs & " months, and "
          end if
          iDays = DateDiff("d",ar Dates(i,0), _
          DateAdd("m", -1*iMths, dDate))
          if iDays < 1 then iDays = 0
          Response.Write iDays & " days"
          Response.Write "<BR>"
          next
          %>




          inamori wrote:[color=blue]
          > Thanks for yoiur programming
          >
          > add one day because of business logic
          >
          > Lease agreement
          >
          > 01/01/2003 12/31/2006 3 years
          >
          > 01/01/2003 01/01/2007 3 years + 1 day
          >
          > That why i need add one day on the end date....
          >
          >
          > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
          > news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...[color=green]
          >> inamori wrote:[color=darkred]
          >>> I face that problems
          >>>
          >>> 07/01/2003 06/30/2006 ---------> it should be 3
          >>>
          >>>
          >>>
          >>> 01/01/2003 02/28/2005 --------->could i get 2 years and 2
          >>> months
          >>>
          >>>
          >>> 01/01/2003 03/01/2005 --------->could i get 2 years and 2
          >>> months and 1 day[/color]
          >>
          >> Could you explain why these aren't the correct results?
          >>
          >> The difference between 7/1/2003 and 6/30/2006 is:
          >> 3 years, 11 months, and 29 days
          >> The difference between 1/1/2003 and 2/28/2005 is:
          >> 2 years, 1 months, and 27 days
          >> The difference between 1/1/2003 and 3/1/2005 is:
          >> 2 years, 2 months, and 0 days
          >>
          >> What is the logic used to determine when to add one day to the
          >> results? Should the difference between 07/01/2003 and 07/01/2003 be
          >> 1 day? How about 07/01 and 07/02?
          >>
          >> This is the code I used to get the above results:
          >> <%
          >> dim arDates(2,1), iYrs, iMths, iDays, i
          >> arDates(0,0) = #2003-07-01#
          >> arDates(0,1) = #2006-06-30#
          >> arDates(1,0) = #2003-01-01#
          >> arDates(1,1) = #2005-02-28#
          >> arDates(2,0) = #2003-01-01#
          >> arDates(2,1) = #2005-03-01#
          >>
          >> for i = 0 to 2
          >> Response.Write "The difference between " & arDates(i,0) & _
          >> " and " & arDates(i,1) & " is: "
          >> iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
          >> Response.Write iYrs & " years, "
          >> iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
          >> if iMths < 12*iYrs then iYrs = iYrs - 1
          >> if iMths - 12*iYrs < 0 then
          >> Response.Write " 0 months, and "
          >> else
          >> Response.Write iMths - 12*iYrs & " months, and "
          >> end if
          >> iDays = DateDiff("d",ar Dates(i,0), _
          >> DateAdd("m", -1*iMths, arDates(i,1)))
          >> if iDays < 1 then iDays = 0
          >> Response.Write iDays & " days"
          >> Response.Write "<BR>"
          >> next
          >> %>
          >>
          >> Bob Barrows
          >> --
          >> Microsoft MVP - ASP/ASP.NET
          >> Please reply to the newsgroup. This email account is my spam trap so
          >> I don't check it very often. If you must reply off-line, then remove
          >> the "NO SPAM"[/color][/color]

          --
          Microsoft MVP - ASP/ASP.NET
          Please reply to the newsgroup. This email account is my spam trap so I
          don't check it very often. If you must reply off-line, then remove the
          "NO SPAM"


          Comment

          • Bob Barrows [MVP]

            #6
            Re: ASP DateDiff

            Yes. That is what I said in my revious response isn't it?
            Just in case you missed it, here it is again:
            *************** *************** *************** *************** ****
            Change the code to this:

            <%
            dim arDates(2,1), iYrs, iMths, iDays, i, dDate
            arDates(0,0) = #2003-07-01#
            arDates(0,1) = #2006-06-30#
            arDates(1,0) = #2003-01-01#
            arDates(1,1) = #2005-02-28#
            arDates(2,0) = #2003-01-01#
            arDates(2,1) = #2005-03-01#

            for i = 0 to 2
            dDate = DateAdd("d",1,a rDates(i,1))
            Response.Write "The difference between " & arDates(i,0) & _
            " and " & dDate & " is: "
            iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
            Response.Write iYrs & " years, "
            iMths=DateDiff( "m",arDates(i,0 ),dDate)
            if iMths < 12*iYrs then iYrs = iYrs - 1
            if iMths - 12*iYrs < 0 then
            Response.Write " 0 months, and "
            else
            Response.Write iMths - 12*iYrs & " months, and "
            end if
            iDays = DateDiff("d",ar Dates(i,0), _
            DateAdd("m", -1*iMths, dDate))
            if iDays < 1 then iDays = 0
            Response.Write iDays & " days"
            Response.Write "<BR>"
            next
            %>

            *************** *************** *************** **************

            inamori wrote:[color=blue]
            > so could I add one date of the end date in your program
            >
            > so i can get what i want???
            >
            >
            > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
            > news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...[color=green]
            >> inamori wrote:[color=darkred]
            >>> I face that problems
            >>>
            >>> 07/01/2003 06/30/2006 ---------> it should be 3
            >>>
            >>>
            >>>
            >>> 01/01/2003 02/28/2005 --------->could i get 2 years and 2
            >>> months
            >>>
            >>>
            >>> 01/01/2003 03/01/2005 --------->could i get 2 years and 2
            >>> months and 1 day[/color]
            >>
            >> Could you explain why these aren't the correct results?
            >>
            >> The difference between 7/1/2003 and 6/30/2006 is:
            >> 3 years, 11 months, and 29 days
            >> The difference between 1/1/2003 and 2/28/2005 is:
            >> 2 years, 1 months, and 27 days
            >> The difference between 1/1/2003 and 3/1/2005 is:
            >> 2 years, 2 months, and 0 days
            >>
            >> What is the logic used to determine when to add one day to the
            >> results? Should the difference between 07/01/2003 and 07/01/2003 be
            >> 1 day? How about 07/01 and 07/02?
            >>
            >> This is the code I used to get the above results:
            >> <%
            >> dim arDates(2,1), iYrs, iMths, iDays, i
            >> arDates(0,0) = #2003-07-01#
            >> arDates(0,1) = #2006-06-30#
            >> arDates(1,0) = #2003-01-01#
            >> arDates(1,1) = #2005-02-28#
            >> arDates(2,0) = #2003-01-01#
            >> arDates(2,1) = #2005-03-01#
            >>
            >> for i = 0 to 2
            >> Response.Write "The difference between " & arDates(i,0) & _
            >> " and " & arDates(i,1) & " is: "
            >> iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
            >> Response.Write iYrs & " years, "
            >> iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
            >> if iMths < 12*iYrs then iYrs = iYrs - 1
            >> if iMths - 12*iYrs < 0 then
            >> Response.Write " 0 months, and "
            >> else
            >> Response.Write iMths - 12*iYrs & " months, and "
            >> end if
            >> iDays = DateDiff("d",ar Dates(i,0), _
            >> DateAdd("m", -1*iMths, arDates(i,1)))
            >> if iDays < 1 then iDays = 0
            >> Response.Write iDays & " days"
            >> Response.Write "<BR>"
            >> next
            >> %>
            >>
            >> Bob Barrows
            >> --
            >> Microsoft MVP - ASP/ASP.NET
            >> Please reply to the newsgroup. This email account is my spam trap so
            >> I don't check it very often. If you must reply off-line, then remove
            >> the "NO SPAM"[/color][/color]

            --
            Microsoft MVP - ASP/ASP.NET
            Please reply to the newsgroup. This email account is my spam trap so I
            don't check it very often. If you must reply off-line, then remove the
            "NO SPAM"


            Comment

            • Inamori Izumi

              #7
              Re: ASP DateDiff

              HI, I have tried your program

              The output is something like that
              The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months, and 0
              days
              The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months, and 0
              days
              The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months, and 1
              days

              But actually what i want is

              The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months, and 1
              days
              The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months, and 1
              days
              The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months, and 2
              days

              can it be done? is it really logic error in computer mechanism



              "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
              news:OJexr$oiEH A.140@TK2MSFTNG P12.phx.gbl...[color=blue]
              > Yes. That is what I said in my revious response isn't it?
              > Just in case you missed it, here it is again:
              > *************** *************** *************** *************** ****
              > Change the code to this:
              >
              > <%
              > dim arDates(2,1), iYrs, iMths, iDays, i, dDate
              > arDates(0,0) = #2003-07-01#
              > arDates(0,1) = #2006-06-30#
              > arDates(1,0) = #2003-01-01#
              > arDates(1,1) = #2005-02-28#
              > arDates(2,0) = #2003-01-01#
              > arDates(2,1) = #2005-03-01#
              >
              > for i = 0 to 2
              > dDate = DateAdd("d",1,a rDates(i,1))
              > Response.Write "The difference between " & arDates(i,0) & _
              > " and " & dDate & " is: "
              > iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
              > Response.Write iYrs & " years, "
              > iMths=DateDiff( "m",arDates(i,0 ),dDate)
              > if iMths < 12*iYrs then iYrs = iYrs - 1
              > if iMths - 12*iYrs < 0 then
              > Response.Write " 0 months, and "
              > else
              > Response.Write iMths - 12*iYrs & " months, and "
              > end if
              > iDays = DateDiff("d",ar Dates(i,0), _
              > DateAdd("m", -1*iMths, dDate))
              > if iDays < 1 then iDays = 0
              > Response.Write iDays & " days"
              > Response.Write "<BR>"
              > next
              > %>
              >
              > *************** *************** *************** **************
              >
              > inamori wrote:[color=green]
              > > so could I add one date of the end date in your program
              > >
              > > so i can get what i want???
              > >
              > >
              > > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
              > > news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...[color=darkred]
              > >> inamori wrote:
              > >>> I face that problems
              > >>>
              > >>> 07/01/2003 06/30/2006 ---------> it should be 3
              > >>>
              > >>>
              > >>>
              > >>> 01/01/2003 02/28/2005 --------->could i get 2 years and 2
              > >>> months
              > >>>
              > >>>
              > >>> 01/01/2003 03/01/2005 --------->could i get 2 years and 2
              > >>> months and 1 day
              > >>
              > >> Could you explain why these aren't the correct results?
              > >>
              > >> The difference between 7/1/2003 and 6/30/2006 is:
              > >> 3 years, 11 months, and 29 days
              > >> The difference between 1/1/2003 and 2/28/2005 is:
              > >> 2 years, 1 months, and 27 days
              > >> The difference between 1/1/2003 and 3/1/2005 is:
              > >> 2 years, 2 months, and 0 days
              > >>
              > >> What is the logic used to determine when to add one day to the
              > >> results? Should the difference between 07/01/2003 and 07/01/2003 be
              > >> 1 day? How about 07/01 and 07/02?
              > >>
              > >> This is the code I used to get the above results:
              > >> <%
              > >> dim arDates(2,1), iYrs, iMths, iDays, i
              > >> arDates(0,0) = #2003-07-01#
              > >> arDates(0,1) = #2006-06-30#
              > >> arDates(1,0) = #2003-01-01#
              > >> arDates(1,1) = #2005-02-28#
              > >> arDates(2,0) = #2003-01-01#
              > >> arDates(2,1) = #2005-03-01#
              > >>
              > >> for i = 0 to 2
              > >> Response.Write "The difference between " & arDates(i,0) & _
              > >> " and " & arDates(i,1) & " is: "
              > >> iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
              > >> Response.Write iYrs & " years, "
              > >> iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
              > >> if iMths < 12*iYrs then iYrs = iYrs - 1
              > >> if iMths - 12*iYrs < 0 then
              > >> Response.Write " 0 months, and "
              > >> else
              > >> Response.Write iMths - 12*iYrs & " months, and "
              > >> end if
              > >> iDays = DateDiff("d",ar Dates(i,0), _
              > >> DateAdd("m", -1*iMths, arDates(i,1)))
              > >> if iDays < 1 then iDays = 0
              > >> Response.Write iDays & " days"
              > >> Response.Write "<BR>"
              > >> next
              > >> %>
              > >>
              > >> Bob Barrows
              > >> --
              > >> Microsoft MVP - ASP/ASP.NET
              > >> Please reply to the newsgroup. This email account is my spam trap so
              > >> I don't check it very often. If you must reply off-line, then remove
              > >> the "NO SPAM"[/color][/color]
              >
              > --
              > Microsoft MVP - ASP/ASP.NET
              > Please reply to the newsgroup. This email account is my spam trap so I
              > don't check it very often. If you must reply off-line, then remove the
              > "NO SPAM"
              >
              >[/color]


              Comment

              • Bob Barrows [MVP]

                #8
                Re: ASP DateDiff

                I goofed. The code should be:


                <%
                dim arDates(2,1), iYrs, iMths, iDays, i, dDate
                arDates(0,0) = #2003-07-01#
                arDates(0,1) = #2006-06-30#
                arDates(1,0) = #2003-01-01#
                arDates(1,1) = #2005-02-28#
                arDates(2,0) = #2003-01-01#
                arDates(2,1) = #2005-03-01#

                for i = 0 to 2
                dDate = DateAdd("d",1,a rDates(i,1))
                Response.Write "The difference between " & arDates(i,0) & _
                " and " & arDates(i,1) & " is: "
                iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
                Response.Write iYrs & " years, "
                iMths=DateDiff( "m",arDates(i,0 ),dDate)
                if iMths < 12*iYrs then iYrs = iYrs - 1
                if iMths - 12*iYrs < 0 then
                Response.Write " 0 months, and "
                else
                Response.Write iMths - 12*iYrs & " months, and "
                end if
                iDays = DateDiff("d",ar Dates(i,0), _
                DateAdd("m", -1*iMths, dDate))
                if iDays < 1 then iDays = 0
                Response.Write iDays & " days"
                Response.Write "<BR>"
                next
                %>



                Inamori Izumi wrote:[color=blue]
                > HI, I have tried your program
                >
                > The output is something like that
                > The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months,
                > and 0 days
                > The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months,
                > and 0 days
                > The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months,
                > and 1 days
                >
                > But actually what i want is
                >
                > The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months,
                > and 1 days
                > The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months,
                > and 1 days
                > The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months,
                > and 2 days
                >
                > can it be done? is it really logic error in computer mechanism
                >
                >
                >
                > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                > news:OJexr$oiEH A.140@TK2MSFTNG P12.phx.gbl...[color=green]
                >> Yes. That is what I said in my revious response isn't it?
                >> Just in case you missed it, here it is again:
                >> *************** *************** *************** *************** ****
                >> Change the code to this:
                >>
                >> <%
                >> dim arDates(2,1), iYrs, iMths, iDays, i, dDate
                >> arDates(0,0) = #2003-07-01#
                >> arDates(0,1) = #2006-06-30#
                >> arDates(1,0) = #2003-01-01#
                >> arDates(1,1) = #2005-02-28#
                >> arDates(2,0) = #2003-01-01#
                >> arDates(2,1) = #2005-03-01#
                >>
                >> for i = 0 to 2
                >> dDate = DateAdd("d",1,a rDates(i,1))
                >> Response.Write "The difference between " & arDates(i,0) & _
                >> " and " & dDate & " is: "
                >> iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
                >> Response.Write iYrs & " years, "
                >> iMths=DateDiff( "m",arDates(i,0 ),dDate)
                >> if iMths < 12*iYrs then iYrs = iYrs - 1
                >> if iMths - 12*iYrs < 0 then
                >> Response.Write " 0 months, and "
                >> else
                >> Response.Write iMths - 12*iYrs & " months, and "
                >> end if
                >> iDays = DateDiff("d",ar Dates(i,0), _
                >> DateAdd("m", -1*iMths, dDate))
                >> if iDays < 1 then iDays = 0
                >> Response.Write iDays & " days"
                >> Response.Write "<BR>"
                >> next
                >> %>
                >>
                >> *************** *************** *************** **************
                >>
                >> inamori wrote:[color=darkred]
                >>> so could I add one date of the end date in your program
                >>>
                >>> so i can get what i want???
                >>>
                >>>
                >>> "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
                >>> news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...
                >>>> inamori wrote:
                >>>>> I face that problems
                >>>>>
                >>>>> 07/01/2003 06/30/2006 ---------> it should be 3
                >>>>>
                >>>>>
                >>>>>
                >>>>> 01/01/2003 02/28/2005 --------->could i get 2 years and 2
                >>>>> months
                >>>>>
                >>>>>
                >>>>> 01/01/2003 03/01/2005 --------->could i get 2 years and 2
                >>>>> months and 1 day
                >>>>
                >>>> Could you explain why these aren't the correct results?
                >>>>
                >>>> The difference between 7/1/2003 and 6/30/2006 is:
                >>>> 3 years, 11 months, and 29 days
                >>>> The difference between 1/1/2003 and 2/28/2005 is:
                >>>> 2 years, 1 months, and 27 days
                >>>> The difference between 1/1/2003 and 3/1/2005 is:
                >>>> 2 years, 2 months, and 0 days
                >>>>
                >>>> What is the logic used to determine when to add one day to the
                >>>> results? Should the difference between 07/01/2003 and 07/01/2003 be
                >>>> 1 day? How about 07/01 and 07/02?
                >>>>
                >>>> This is the code I used to get the above results:
                >>>> <%
                >>>> dim arDates(2,1), iYrs, iMths, iDays, i
                >>>> arDates(0,0) = #2003-07-01#
                >>>> arDates(0,1) = #2006-06-30#
                >>>> arDates(1,0) = #2003-01-01#
                >>>> arDates(1,1) = #2005-02-28#
                >>>> arDates(2,0) = #2003-01-01#
                >>>> arDates(2,1) = #2005-03-01#
                >>>>
                >>>> for i = 0 to 2
                >>>> Response.Write "The difference between " & arDates(i,0) & _
                >>>> " and " & arDates(i,1) & " is: "
                >>>> iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
                >>>> Response.Write iYrs & " years, "
                >>>> iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
                >>>> if iMths < 12*iYrs then iYrs = iYrs - 1
                >>>> if iMths - 12*iYrs < 0 then
                >>>> Response.Write " 0 months, and "
                >>>> else
                >>>> Response.Write iMths - 12*iYrs & " months, and "
                >>>> end if
                >>>> iDays = DateDiff("d",ar Dates(i,0), _
                >>>> DateAdd("m", -1*iMths, arDates(i,1)))
                >>>> if iDays < 1 then iDays = 0
                >>>> Response.Write iDays & " days"
                >>>> Response.Write "<BR>"
                >>>> next
                >>>> %>
                >>>>
                >>>> Bob Barrows
                >>>> --
                >>>> Microsoft MVP - ASP/ASP.NET
                >>>> Please reply to the newsgroup. This email account is my spam trap
                >>>> so I don't check it very often. If you must reply off-line, then
                >>>> remove the "NO SPAM"[/color]
                >>
                >> --
                >> Microsoft MVP - ASP/ASP.NET
                >> Please reply to the newsgroup. This email account is my spam trap so
                >> I don't check it very often. If you must reply off-line, then remove
                >> the "NO SPAM"[/color][/color]

                --
                Microsoft MVP - ASP/ASP.NET
                Please reply to the newsgroup. This email account is my spam trap so I
                don't check it very often. If you must reply off-line, then remove the
                "NO SPAM"


                Comment

                • inamori

                  #9
                  Re: ASP DateDiff

                  thanks
                  let me test tomorrow when I work
                  "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
                  news:ONZV3R1iEH A.536@TK2MSFTNG P11.phx.gbl ¤¤¼¶¼g...[color=blue]
                  > I goofed. The code should be:
                  >
                  >
                  > <%
                  > dim arDates(2,1), iYrs, iMths, iDays, i, dDate
                  > arDates(0,0) = #2003-07-01#
                  > arDates(0,1) = #2006-06-30#
                  > arDates(1,0) = #2003-01-01#
                  > arDates(1,1) = #2005-02-28#
                  > arDates(2,0) = #2003-01-01#
                  > arDates(2,1) = #2005-03-01#
                  >
                  > for i = 0 to 2
                  > dDate = DateAdd("d",1,a rDates(i,1))
                  > Response.Write "The difference between " & arDates(i,0) & _
                  > " and " & arDates(i,1) & " is: "
                  > iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
                  > Response.Write iYrs & " years, "
                  > iMths=DateDiff( "m",arDates(i,0 ),dDate)
                  > if iMths < 12*iYrs then iYrs = iYrs - 1
                  > if iMths - 12*iYrs < 0 then
                  > Response.Write " 0 months, and "
                  > else
                  > Response.Write iMths - 12*iYrs & " months, and "
                  > end if
                  > iDays = DateDiff("d",ar Dates(i,0), _
                  > DateAdd("m", -1*iMths, dDate))
                  > if iDays < 1 then iDays = 0
                  > Response.Write iDays & " days"
                  > Response.Write "<BR>"
                  > next
                  > %>
                  >
                  >
                  >
                  > Inamori Izumi wrote:[color=green]
                  > > HI, I have tried your program
                  > >
                  > > The output is something like that
                  > > The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months,
                  > > and 0 days
                  > > The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months,
                  > > and 0 days
                  > > The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months,
                  > > and 1 days
                  > >
                  > > But actually what i want is
                  > >
                  > > The difference between 7/1/2003 and 7/1/2006 is: 3 years, 0 months,
                  > > and 1 days
                  > > The difference between 1/1/2003 and 3/1/2005 is: 2 years, 2 months,
                  > > and 1 days
                  > > The difference between 1/1/2003 and 3/2/2005 is: 2 years, 2 months,
                  > > and 2 days
                  > >
                  > > can it be done? is it really logic error in computer mechanism
                  > >
                  > >
                  > >
                  > > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                  > > news:OJexr$oiEH A.140@TK2MSFTNG P12.phx.gbl...[color=darkred]
                  > >> Yes. That is what I said in my revious response isn't it?
                  > >> Just in case you missed it, here it is again:
                  > >> *************** *************** *************** *************** ****
                  > >> Change the code to this:
                  > >>
                  > >> <%
                  > >> dim arDates(2,1), iYrs, iMths, iDays, i, dDate
                  > >> arDates(0,0) = #2003-07-01#
                  > >> arDates(0,1) = #2006-06-30#
                  > >> arDates(1,0) = #2003-01-01#
                  > >> arDates(1,1) = #2005-02-28#
                  > >> arDates(2,0) = #2003-01-01#
                  > >> arDates(2,1) = #2005-03-01#
                  > >>
                  > >> for i = 0 to 2
                  > >> dDate = DateAdd("d",1,a rDates(i,1))
                  > >> Response.Write "The difference between " & arDates(i,0) & _
                  > >> " and " & dDate & " is: "
                  > >> iYrs=DateDiff(" yyyy",arDates(i ,0),dDate)
                  > >> Response.Write iYrs & " years, "
                  > >> iMths=DateDiff( "m",arDates(i,0 ),dDate)
                  > >> if iMths < 12*iYrs then iYrs = iYrs - 1
                  > >> if iMths - 12*iYrs < 0 then
                  > >> Response.Write " 0 months, and "
                  > >> else
                  > >> Response.Write iMths - 12*iYrs & " months, and "
                  > >> end if
                  > >> iDays = DateDiff("d",ar Dates(i,0), _
                  > >> DateAdd("m", -1*iMths, dDate))
                  > >> if iDays < 1 then iDays = 0
                  > >> Response.Write iDays & " days"
                  > >> Response.Write "<BR>"
                  > >> next
                  > >> %>
                  > >>
                  > >> *************** *************** *************** **************
                  > >>
                  > >> inamori wrote:
                  > >>> so could I add one date of the end date in your program
                  > >>>
                  > >>> so i can get what i want???
                  > >>>
                  > >>>
                  > >>> "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> ¦b¶l¥ó
                  > >>> news:%23b$uJC4h EHA.1356@TK2MSF TNGP09.phx.gbl ¤¤¼¶¼g...
                  > >>>> inamori wrote:
                  > >>>>> I face that problems
                  > >>>>>
                  > >>>>> 07/01/2003 06/30/2006 ---------> it should be 3
                  > >>>>>
                  > >>>>>
                  > >>>>>
                  > >>>>> 01/01/2003 02/28/2005 --------->could i get 2 years and 2
                  > >>>>> months
                  > >>>>>
                  > >>>>>
                  > >>>>> 01/01/2003 03/01/2005 --------->could i get 2 years and 2
                  > >>>>> months and 1 day
                  > >>>>
                  > >>>> Could you explain why these aren't the correct results?
                  > >>>>
                  > >>>> The difference between 7/1/2003 and 6/30/2006 is:
                  > >>>> 3 years, 11 months, and 29 days
                  > >>>> The difference between 1/1/2003 and 2/28/2005 is:
                  > >>>> 2 years, 1 months, and 27 days
                  > >>>> The difference between 1/1/2003 and 3/1/2005 is:
                  > >>>> 2 years, 2 months, and 0 days
                  > >>>>
                  > >>>> What is the logic used to determine when to add one day to the
                  > >>>> results? Should the difference between 07/01/2003 and 07/01/2003 be
                  > >>>> 1 day? How about 07/01 and 07/02?
                  > >>>>
                  > >>>> This is the code I used to get the above results:
                  > >>>> <%
                  > >>>> dim arDates(2,1), iYrs, iMths, iDays, i
                  > >>>> arDates(0,0) = #2003-07-01#
                  > >>>> arDates(0,1) = #2006-06-30#
                  > >>>> arDates(1,0) = #2003-01-01#
                  > >>>> arDates(1,1) = #2005-02-28#
                  > >>>> arDates(2,0) = #2003-01-01#
                  > >>>> arDates(2,1) = #2005-03-01#
                  > >>>>
                  > >>>> for i = 0 to 2
                  > >>>> Response.Write "The difference between " & arDates(i,0) & _
                  > >>>> " and " & arDates(i,1) & " is: "
                  > >>>> iYrs=DateDiff(" yyyy",arDates(i ,0),arDates(i,1 ))
                  > >>>> Response.Write iYrs & " years, "
                  > >>>> iMths=DateDiff( "m",arDates(i,0 ),arDates(i,1))
                  > >>>> if iMths < 12*iYrs then iYrs = iYrs - 1
                  > >>>> if iMths - 12*iYrs < 0 then
                  > >>>> Response.Write " 0 months, and "
                  > >>>> else
                  > >>>> Response.Write iMths - 12*iYrs & " months, and "
                  > >>>> end if
                  > >>>> iDays = DateDiff("d",ar Dates(i,0), _
                  > >>>> DateAdd("m", -1*iMths, arDates(i,1)))
                  > >>>> if iDays < 1 then iDays = 0
                  > >>>> Response.Write iDays & " days"
                  > >>>> Response.Write "<BR>"
                  > >>>> next
                  > >>>> %>
                  > >>>>
                  > >>>> Bob Barrows
                  > >>>> --
                  > >>>> Microsoft MVP - ASP/ASP.NET
                  > >>>> Please reply to the newsgroup. This email account is my spam trap
                  > >>>> so I don't check it very often. If you must reply off-line, then
                  > >>>> remove the "NO SPAM"
                  > >>
                  > >> --
                  > >> Microsoft MVP - ASP/ASP.NET
                  > >> Please reply to the newsgroup. This email account is my spam trap so
                  > >> I don't check it very often. If you must reply off-line, then remove
                  > >> the "NO SPAM"[/color][/color]
                  >
                  > --
                  > Microsoft MVP - ASP/ASP.NET
                  > Please reply to the newsgroup. This email account is my spam trap so I
                  > don't check it very often. If you must reply off-line, then remove the
                  > "NO SPAM"
                  >
                  >[/color]


                  Comment

                  Working...