9 Replies Latest reply on Mar 9, 2017 8:47 AM by philmodjunk

    Add Minutes to Time

    alc

      Title

      Add Minutes to Time

      Post

      Really dumb question: This seems like it should be very easy, but so far I'm stumped.

      Given 2 fields

      1. being the start time of an event,

      2. the other being the number of minutes something took (as entered by a user)

      how would you add the minutes to the start time, I keep thinking the min.s need to be converted to time, but not sure how.

      Thanks in advance, xandra

        • 1. Re: Add Minutes to Time
          philmodjunk

          If you enter time as minutes in a number field, this calculation can be used to produce the end time of the event:

          StartTime + 60 * EventTimeInMinutes

          Select Time as the calculation's return type.,

          This works because time fields store time as an integer that counts the number of seconds elapsed since midnight. All you have to do is compute the correct number of seconds to add to your start time.

          • 2. Re: Add Minutes to Time
            alc

            Thanks again Phil, That worked like a charm.

            Can I assume the If I were adding in Hours (rather than min's) would be:

            StartTime + (360 * EventTimeInMinutes)

            • 3. Re: Add Minutes to Time
              raybaudi
              No ! There are 3600 seconds in an hour.
              • 4. Re: Add Minutes to Time
                alc
                Whoops! Glad I asked.
                • 5. Re: Add Minutes to Time
                  philmodjunk

                  IF you are adding hours and minutes to the same start time, you might want to just use a Time Field and then your calculation becomes:

                  StartTimeField + ElapsedTimeField

                  • 6. Re: Add Minutes to Time
                    mikerevans

                    Hi Phil,

                     

                    How would this be expressed as part of an IF statement in a script?

                     

                    Thanks

                    Mike

                    • 7. Re: Add Minutes to Time
                      philmodjunk

                      Exactly the same, but an If step requires a Boolean result value of True (Or number other than zero or null) or False (values Null or zero) will be expected in order to control which section of code is next executed.

                       

                      You've given no indication as to how you would use such a calculation in a script but you might write it like this:

                       

                      If [  ( StartTime + 60 * EventTimeInMinutes ) < GetAstime ( "12:00 pm" ) ]

                       

                      This then checks to see if the calculated time falls before noon. Note the need to avoid comparing apples to oranges here. Since the calculation to the left of < is of type time, I need to compare it to a value of type time on the right. There are a number of different ways to get a value of type time, this is just one possibility here.

                      • 8. Re: Add Minutes to Time
                        mikerevans

                        I'm looking to set a TargetDate from a Priority field.

                         

                        If i format the cell as a calculation the above works perfectly. However there are 3 priorities.

                         

                        Priority

                        1 - 4 hours

                        2 - 24 hours

                        3 - 28 days

                         

                        I was originally just wanting to add the amount of seconds to CreateDate, to make TargetDate. I think I need a script to run on enter of TargetDate to read what is in Priority, and add the relevant number of seconds.

                         

                        Then I realised this may not be feasible anyway as I need to miss out non business hours and days!

                         

                        Mike

                        • 9. Re: Add Minutes to Time
                          philmodjunk

                          Dates store a number that's the number of days since 12/31/0000. Time fields store a number that's the number of seconds since midnight. So you can't use a time calculation with a date field.

                           

                          What you need is a field of type TimeStamp. This field combines both a date and a time. It stores a value that's the number of seconds since midnight of 12/31/0000. So now you can add and subtract time from this value to get a result (Of type timestamp) that includes a date as well as a time.

                           

                          You'll need all three priority values in seconds, not hours or days.

                           

                          StartTimeStamp +

                          Case ( Priority = 1  ; 4 * 3600 ;

                                      Priority - 2 ; 24 * 3600 ;

                                      Priority = 3 ; 28 * 24 * 3600

                                     )

                           

                          Result type would be TimeStamp

                           

                          PS 1

                           

                          You can also use Choose in place of case here. the syntax differs a bit, but it also works here.

                           

                          PS 2

                           

                          I would not actually "hard code" the different time intervals and priorities into a calculation like this. I'd put this data in a table with one record for each priority and use an auto-enter calculation with a relationship to compute the TargetTimeStamp. That way, users can modify the priorities and time intervals by editing data in that table instead of needing a FileMaker developer to redefine the calculation.