6 Replies Latest reply on Jan 23, 2012 7:55 AM by blue22

    A Question About Time

    StephenWonfor

      Hello all...

       

      I am doing some gyrations with times in Filemaker and just want to clarify a few point before I code myself into a corner.

       

      This script produces different results:

       

      Set Variable [ $$EndTime; Value:Max(schedule_HAUL|Truck00|::StartTime) ]

      Set Variable [ $$LocalTime; Value:Schedule::_gzStartTime ]

       

      StartTime is a time field in a related tale.

      _gzStartTime is a global time field in the local table. The value is set from a menu with hardcoded "times" in it (for the user experience)

       

      $$EndTime yields "18:00:00"

      $$LocalTime yields "6:00 PM"

       

      So I tried this: Set Variable [ $$LocalTime; Value: getastime(Schedule::_gzStartTime) ]

       

      $$LocalTime yields "6:00 PM". I was sort of expecting "18:00:00" or perhaps 64800 (would be ideal).

       

      So I tried this: Set Variable [ $$LocalTime; Value: getasnumber(Schedule::_gzStartTime) ]

       

      $$LocalTime yields "64800". Perfect.

       

      Set Variable [ $$LocalTime; Value: getasnumber("7:00 PM) ] rather predictably yields 700. Which is of little use here.


      So, s this the best way to handle time comparisons - boil the time fields down to component seconds?

      Stephen

       

       

      "Time moves in one direction, memory in another." --- William Gibson

        • 1. Re: A Question About Time
          timwhisenant

          Steven,

           

           

           

          I have a time calculation system for time sheets and yes, I do believe all time got converted to seconds and then math functions were performed and then my components were converted back for further use. Seconds seemed to be the best way for me to deal with time.

           

           

           

          Tim

           

           

           

          Timothy R Whisenant

           

          Plastic Fusion Fabricators, Inc.

           

          (256) 852-0378  x. 244

           

          Fax: (256) 852-0388

          • 2. Re: A Question About Time
            BruceHerbach

            Hi Stephen,

             

            Try using Set Variable [ $$LocalTime; Value: getasnumber(getastime("7:00

            PM")) ]

             

            This will convert text to time first then a number yielding 68400.  Just

            substitute the problem field for the text string and you should be set.

             

            Bruce Herbach

            • 3. Re: A Question About Time
              thosliot

              Stephen

               

              Have you tried comparing $$EndTime and $$LocalTime?

               

              Given that all fields involved are of type Time, I believe that any comparison between the two variables will occur in Time-space - for example, the comparison $$EndTime = $$LocalTime will yield True, since both represent the same time (regardless of their differing 'as entered' Text values)

               

              cheers

               

              Tom

               

              On 20 Jan 2012, at 19:39, StephenWonfor wrote

               

              This script produces different results:

               

              Set Variable $$EndTime; Value:Max(schedule_HAUL

              Set Variable $$LocalTime; Value:Schedule::_gzStartTime

               

              StartTime is a time field in a related tale.

              _gzStartTime is a global time field in the local table.  The value is set from a menu with hardcoded "times" in it (for the user experience)

               

              $$EndTime yields "18:00:00"

              $$LocalTime yields "6:00 PM"

               

              So I tried this:  Set Variable $$LocalTime; Value: getastime(Schedule::_gzStartTime)

               

              $$LocalTime yields "6:00 PM".  I was sort of expecting "18:00:00" or perhaps 64800 (would be ideal).

               

              So I tried this:  Set Variable $$LocalTime; Value: getasnumber(Schedule::_gzStartTime)

               

              $$LocalTime yields "64800".  Perfect. 

               

              Set Variable [ $$LocalTime; Value: getasnumber("7:00 PM) ]  rather predictably yields 700.  Which is of little use here.

               

               

              So, s this the best way to handle time comparisons - boil the time fields down to component seconds?

               

              Stephen

               

              • 4. Re: A Question About Time

                Stephen,

                 

                The problem with your approach is the use of variables which hold per se text, not numbers or the time.

                Either you convert times to numbers at their first appearance like

                $$time = getasnumber ( time ( hours; minutes; seconds) )

                or even better

                $$ time = getasnumber ( Timestamp ( date (); time () ) )

                 

                or you resort to using fields of type time (or timestamp).

                 

                You might want to take a glance at < http://fmdiff.com/fm/agecalc.html> about time calculations.

                 

                 

                Winfried

                 

                --

                Check out the new FMDiff 2.0 to compare two FileMaker files and test for file corruption at <http://www.fmdiff.com

                • 5. Re: A Question About Time
                  StephenWonfor

                  Bruce

                   

                  Thanks.  That's rather cool.

                   

                  Stephen

                  • 6. Re: A Question About Time
                    blue22

                    As Winfried mentioned you may want to use fields of type timestamp instead of type time.

                     

                    I'm sure that you have considered this but if your time calculations might happen across days using time calculations alone won't correctly calculate your answer. Timestamps add a date factor into your seconds count.

                     

                    The total hours worked with a start time of 10:00 pm today and an end time of 1:00 am tomoorow when using time functions alone would get you a negative 21 hours. While a timestamp calculation would get you 3 hours.