Calculation of time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nhaider@kockw.com

    Calculation of time

    Hi all

    I am trying to calculate the two different time field. When I entered
    in field like 7:00 and 15:00 the result is 8 hrs but when I entered
    15:30 the result is also 8 hrs. I am using the following VBA code

    Private Sub TimeToDay_After Update()

    'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60

    End Sub

    Please help me to solve this problem.

    Thanks in advance.

    Naushad
  • Ed Robichaud

    #2
    Re: Calculation of time

    You'll need to format your [TotDay] control to display at least 1 decimal
    place to see fractions of an hour, i.e. 1.45 hours. If you want to display
    your time result as hrs:min, then you'll need to roll-your-own format.
    -Ed


    <nhaider@kockw. comwrote in message
    news:096c2f33-b09e-4033-a42a-ef79660062d3@q7 0g2000hsb.googl egroups.com...
    Hi all
    >
    I am trying to calculate the two different time field. When I entered
    in field like 7:00 and 15:00 the result is 8 hrs but when I entered
    15:30 the result is also 8 hrs. I am using the following VBA code
    >
    Private Sub TimeToDay_After Update()
    >
    'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
    >
    End Sub
    >
    Please help me to solve this problem.
    >
    Thanks in advance.
    >
    Naushad

    Comment

    • Salad

      #3
      Re: Calculation of time

      Ed Robichaud wrote:
      You'll need to format your [TotDay] control to display at least 1 decimal
      place to see fractions of an hour, i.e. 1.45 hours. If you want to display
      your time result as hrs:min, then you'll need to roll-your-own format.
      -Ed
      >
      Expanding on what you wrote...
      ts = #7:00#
      te = #15:30#
      ? timeserial(0,da tediff("n",ts,t e),0)
      8:30:00 AM
      ? Format(timeseri al(0,datediff(" n",ts,te),0),"h .n")
      8.30

      The number to the right of the decimal point is in minutes, not a
      decimal equivalent.

      Creeps
      http://www.youtube.com/watch?v=aUgTCpLJOEU&NR=1
      >
      <nhaider@kockw. comwrote in message
      news:096c2f33-b09e-4033-a42a-ef79660062d3@q7 0g2000hsb.googl egroups.com...
      >
      >>Hi all
      >>
      >>I am trying to calculate the two different time field. When I entered
      >>in field like 7:00 and 15:00 the result is 8 hrs but when I entered
      >>15:30 the result is also 8 hrs. I am using the following VBA code
      >>
      >>Private Sub TimeToDay_After Update()
      >>
      >>'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
      >>
      >>End Sub
      >>
      >>Please help me to solve this problem.
      >>
      >>Thanks in advance.
      >>
      >>Naushad
      >
      >
      >

      Comment

      • nhaider@kockw.com

        #4
        Re: Calculation of time

        On Feb 18, 8:09 pm, Salad <o...@vinegar.c omwrote:
        Ed Robichaud wrote:
        You'll need to format your [TotDay] control to display at least 1 decimal
        place to see fractions of an hour, i.e. 1.45 hours.   If you want to display
        your time result as hrs:min, then you'll need to roll-your-own format.
        -Ed
        >
        Expanding on what you wrote...
        ts = #7:00#
        te = #15:30#
        ? timeserial(0,da tediff("n",ts,t e),0)
        8:30:00 AM
        ? Format(timeseri al(0,datediff(" n",ts,te),0),"h .n")
        8.30
        >
        The number to the right of the decimal point is in minutes, not a
        decimal equivalent.
        >
        Creepshttp://www.youtube.com/watch?v=aUgTCpL JOEU&NR=1
        >
        >
        >
        >
        >
        <nhai...@kockw. comwrote in message
        news:096c2f33-b09e-4033-a42a-ef79660062d3@q7 0g2000hsb.googl egroups.com...
        >
        >Hi all
        >
        >I am trying to calculate the two different time field. When I entered
        >in field like 7:00 and 15:00 the result is 8 hrs but when I entered
        >15:30 the result is also 8 hrs. I am using the following VBA code
        >
        >Private Sub TimeToDay_After Update()
        >
        >'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
        >
        >End Sub
        >
        >Please help me to solve this problem.
        >
        >Thanks in advance.
        >
        >Naushad- Hide quoted text -
        >
        - Show quoted text -
        Hi Creep

        I did [TotDay] control to display at least 1 decimal place to see
        fractions of an hour and expanded my code as per your suggestion but
        the result is same i.e. the whole no. not fraction.

        Please help me to solve this problem.

        Naushad

        Comment

        • Arch

          #5
          Re: Calculation of time

          On Wed, 20 Feb 2008 22:44:32 -0800 (PST), nhaider@kockw.c om wrote:
          >>
          >>
          <nhai...@kockw. comwrote in message
          >news:096c2f3 3-b09e-4033-a42a-ef79660062d3@q7 0g2000hsb.googl egroups.com...
          >>
          >>Hi all
          >>
          >>I am trying to calculate the two different time field. When I entered
          >>in field like 7:00 and 15:00 the result is 8 hrs but when I entered
          >>15:30 the result is also 8 hrs. I am using the following VBA code
          >>
          >>Private Sub TimeToDay_After Update()
          >>
          >>'Me.TotDay = (DateDiff("n", Me.TimeFromDay, Me.TimeToDay) - 30) / 60
          >>
          >>End Sub
          >>
          >>Please help me to solve this problem.
          >>
          >>Thanks in advance.
          >>
          >>Naushad- Hide quoted text -
          >>
          >- Show quoted text -
          >
          >Hi Creep
          >
          >I did [TotDay] control to display at least 1 decimal place to see
          >fractions of an hour and expanded my code as per your suggestion but
          >the result is same i.e. the whole no. not fraction.
          >
          >Please help me to solve this problem.
          >
          >Naushad
          Is the TotDay control bound to a field? Possibly an integer field?

          Perhaps you should look at the formatting of your control again.

          ?(datediff("n", #7:00#,#15:00#)-30)/60
          7.5

          What's with that "- 30"? It looks as though someone might be
          intending some sort of rounding.

          Comment

          Working...