Simple Time Math

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • markstaylor
    Indigo Rose Customer
    • Oct 2003
    • 296

    Simple Time Math

    How can I get the total time given two Time entry's
    I have to have an entry for begining time and ending time and then give a total of that time.
    Example

    1:30 pm
    3:05 pm
    = 1.35

    Thanks
    SELECT * FROM Users WHERE IQ > 0;
    o rows Returned
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    #2
    How is the time being entered, is it entered by the user or generated by a system function? Will the time being entered always be in the format you specified?

    hour:mins<space>[am|pm]

    If it will always be in that order, I would suggest you break apart the string using String.Find function find the : then extract the hours, find the <space> and then extract the minutes then extract whether it was AM or PM. If PM then add 12 to the hours entry and multiply by 60 to get the total number of minutes. Then add that to the minutes entry and you have the number of minutes since midnight. Do this for both begin time and end time and subtract. Then divide the total time by 60 using Math.Floor to determine the number of hours and the remainder will be the number of minutes.

    You may also want to check and see if the end time is less than the begin time. If it is, then add 1440 to the time to represent an additional day in minutes.

    Hope that helps.

    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment

    • TJ_Tigger
      Indigo Rose Customer
      • Sep 2002
      • 3159

      #3
      I thought I would throw this one out there as well. I learned this one from Worm. If you are using the system to determine a begin and end time this is what I have done.

      Code:
      --Determine Basetime when the timed event began
      basetime = DLL.CallFunction(_SystemFolder .. "\\winmm.dll", "timeGetTime", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
      --Determine the Endtime when the timed event stopped
      endtime =  DLL.CallFunction(_SystemFolder .. "\\winmm.dll", "timeGetTime", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
      --Determine the delta between the two, the Elapsed time will be displayed in seconds.
      elapsedtime = ((String.ToNumber(endtime) - String.ToNumber(basetime)) / 1000);
      --This code then converts the seconds into a readabe format hh:mm:ss and sets that to a label within AMS
      hours = Math.Floor(elapsedtime / 3600);
      mins = Math.Floor((elapsedtime - (hours * 3600)) / 60);
      secs = Math.Floor(elapsedtime - ((hours*3600)+(mins*60)));
      		
      if hours < 10 then
      	hours = "0"..hours;
      end
      if mins < 10 then
      	mins = "0"..mins;
      end
      if secs < 10 then
      	secs = "0"..secs;
      end
      	
      Label.SetText("Timer", hours..":"..mins..":"..secs)
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment

      • markstaylor
        Indigo Rose Customer
        • Oct 2003
        • 296

        #4
        The format is a

        End Time
        Inputbox -> 3:05

        Start Time
        Inputbox -> 1:30

        both have check boxes for Am or Pm

        I tried following your first example, but I can't get it working yet.
        SELECT * FROM Users WHERE IQ > 0;
        o rows Returned

        Comment

        • Stefan_M
          Indigo Rose Customer
          • Nov 2003
          • 315

          #5
          Did you mean something like that. (see attachment)


          Stefan_M
          Attached Files
          "With a rubber duck, one's never alone."

          Douglas Adams, The Hitchhiker's Guide to the Galaxy

          Comment

          • TJ_Tigger
            Indigo Rose Customer
            • Sep 2002
            • 3159

            #6
            Stefan

            You beat me to it. I have posted mine as well. My mid day got away from me. Oh well


            Tigg
            Attached Files
            Last edited by TJ_Tigger; 01-26-2005, 01:35 PM.
            TJ-Tigger
            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
            "Draco dormiens nunquam titillandus."
            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

            Comment

            • Intrigued
              Indigo Rose Customer
              • Dec 2003
              • 6138

              #7
              Originally posted by TJ_Tigger
              Stefan

              You beat me to it. I have posted mine as well. My mid day got away from me. Oh well


              Tigg
              Now it gets weird... I just was working on a function like this and I called my function the same name TJ_TIGGER you called your project.

              Spoooky...
              Intrigued

              Comment

              • TJ_Tigger
                Indigo Rose Customer
                • Sep 2002
                • 3159

                #8
                Sounds like a Twilight Zone story.
                TJ-Tigger
                "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                "Draco dormiens nunquam titillandus."
                Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                Comment

                • markstaylor
                  Indigo Rose Customer
                  • Oct 2003
                  • 296

                  #9
                  Many thanks, I was way off on what I was doing.

                  Seems so simple looking at your projects.

                  Thanks once again
                  SELECT * FROM Users WHERE IQ > 0;
                  o rows Returned

                  Comment

                  Working...
                  X