9 Replies Latest reply on Feb 1, 2017 1:10 PM by siplus

    Set time field not displaying as intended

    thehalpeen

      I have a global time field called gStartTime formatted via the Inspector as hh:mm and 12 hour. It can be populated from a list of values in 30 minute slots ie 8:30 AM, 9:00 AM, 9:30 AM, 10:00 AM, 10:30 AM, etc. This field is used to set another 'time' field in another table - it displays as HH:MM.

       

      However, I have a button with a script  - (Menu::gStartTime + 300)/1 - that adds 15 minutes to the drop down times. So if a user selects 10:00 AM from the Dropdown list, they can then add 15 minutes via the button.

       

      The problem is that the field that it sets in the other table, displays as HH:MM:SS and not HH:MM. As I said, if the user just selects the values from the dropdown list, it will display as I intended, but adding the 15 minutes, changes the formatting to include the 'seconds'. Is this solveable?

        • 1. Re: Set time field not displaying as intended
          mikebeargie

          Display is display, but time in filemaker is always STORED in HH:MM:SS format

          FileMaker Pro 15 Help

           

          If I enter 10:00 into a field, filemaker will store it as 10:00:00.

           

          Display settings on a field can be changes on the object level. This is under the inspector in the last tab (data) towards the bottom. Select the icon of a watch to indicate the field is displaying time, then you can set it to display in 12/24 form with a myriad of options for formatting.

           

          Calculations should always be done with the HH:MM:SS format, you can use the Time() function I linked to above to convert as needed.

           

          EG If I wanted to add 15 minutes, I would just do:

          Set Field [ globalTime1 ; globalTime1 + Time( 0 ; 15 ; 0 ) ]

          1 of 1 people found this helpful
          • 2. Re: Set time field not displaying as intended
            thehalpeen

            Mike,

             

            Thanks.

            It's strange how it accepts the times from the value list , but not if that value is amended with that little script. If I type in 9:15 AM it will work - but typing can be a bit of a messy task for a user.

             

            Entry 1 - all data from Value list and then this sets time fields in another table - Start Time and End time

            pre.PNG

            Entry - I added 15 mins via your script

            amended.PNG

            The Result in the 'other' table - the top shows without the seconds, but the bottom has the seconds - not as neat.

            result.PNG

            It's more for presentation purposes. We don't need to see the seconds. Its live with it, or  make a value list that has a list of time- every 15 min - 9:00. 9:15 9:30, etc. It'll be a long list.

             

            The reason I was going to use the drop-down is that it's awkward at times typing in times.

            • 3. Re: Set time field not displaying as intended
              philmodjunk

              You may need to post the actual script so that we can see what is or is not working here.

               

              Time and timestamp data are stored as the total number of seconds so 15 minutes would 15 * 60 or 900 seconds.

               

              Set field [ YourTable::TimeField ; YourTable::TimeField + 900 ]

               

              Would thus increment the time by 15 minutes.

               

              Mike is achieving the same result by using the Time function which converts the value into seconds for you so it should work as well and it a bit more self documenting.

               

              What you posted

              (Menu::gStartTime + 300)/1

               

              Doesn't really make sense.

              • 4. Re: Set time field not displaying as intended
                thehalpeen

                Phil,

                 

                I have attached a sample file to illustrate the issue.

                • I have a Value list of times
                • Two Tables/Layouts - GLOBALS and EVENTS
                • Thrre fields in the GLOBAL table - gStartTime1,  gStartTime2, gStartTime3
                • It starts with the Globals Layout (Default)
                • When you populate two of the fields with values from the Value List and the other field manually - it display perfectly - no seconds displayed in the portal view.
                • If I add 5 mins via the 'plus' button and create  a record - the display changes to include seconds in the portal on the new record.

                Strange!!

                • 5. Re: Set time field not displaying as intended
                  philmodjunk

                  mikebeargie Gave you the answer in response #1. You just need to select the time fields in the portal row while in layout mode and specify a time format that does not include seconds.

                   

                  Your expressions for your calculated values divide by 1 which makes no sense and can be removed.

                   

                  You can also change your script to be a lot simpler. You just need one script step:

                   

                  Set Field By Name [ Get ( ScriptParameter ) ; GetField ( Get ( ScriptParameter ) ) + 300 ]

                   

                  Then use:

                   

                  getfieldname ( GLOBALS::gStartTime1 )

                   

                  as your script parameter (for the first field, use a different field reference for each of the other two.)

                  • 6. Re: Set time field not displaying as intended
                    thehalpeen

                    Phil.

                     

                    Apologies again. The problem occurs when I concatenate the StartTime with the EndTime (this is for presentation purposes) -see image below:

                    Portal with Combined Text.PNG

                    I can live with it, if I choose to display the actual StartTime and EndTime fields, with a little 'hyphen in a seperate box stuck between them. Less elegant - but it will works.

                     

                    Re your new script

                    I've never knew about that technique before. I've tried to implement it - but I get a '?' in the Global fields when I press the 'plus' button.

                     

                    I have attached the revised file with my attempt at implementing your script.

                     

                    !

                    • 7. Re: Set time field not displaying as intended
                      philmodjunk

                      In the script, you have a parenthesis in the wrong place. Note the red parenthesis in this expression:

                       

                      GetField ( Get ( ScriptParameter ) ) + 300

                       

                      As for formatting the time. You have a text string, not time in that calculation field so data formatting can't format it. But there are two ways to resolve that issue:

                       

                      a) Use a pair of merge fields with a - between them. You can select this single block of layout text and use the inspector to apply time formatting to it.

                      b) In the calculation, break up the values into hours and minutes and use the calculation to format it into 12 hour time and with the proper leading zeroes for minutes.

                       

                      The merge fields are MUCH simpler to set up, so I'd use that approach if at all possible.

                       

                      I've demonstrated both methods in the attached file as well as fixed the script.

                       

                      Note on merge fields and text formatting:

                       

                      The block of text containing one or more merge field is often much wider than a conventional field and this can make it hard to fit it into a portal row. I've used a trick here that I learned from this community: The formatting applied to the characters from the merge field's value are all determined by the text formatting you specify for the first < of the merge field. So to make for a smaller block of text, I selected all text after that first < character and specified a smaller font size. In a production database, I would have selected a much smaller font size, but for this file, I kept the text large enough to read.

                      • 8. Re: Set time field not displaying as intended
                        thehalpeen

                        Simple - but brilliant. Don't know why I didn't think of the merge fields. Thanks!

                        • 9. Re: Set time field not displaying as intended
                          siplus

                          if you want to add 15 min to a time field you should set it to what it was + 900, not to +300.

                           

                          calcs on times uses seconds, and 15 min * 60 secs = 900.

                           

                          times are stored as integers which correspond to seconds away from 0, 0 being 00:00:00.

                           

                          getasnumber(time(0;0;0)) gives 0

                           

                          getasnumber(time(1;0;0)) gives 3600   (1 * 60 * 60  +  0* 60  + 0)

                           

                          getasnumber(time(1;1;1)) gives 3661 (1*60^2+ 1*60^1 + 1*60^0)