Jump to content
Server Maintenance This Week. ×

Time input simplified


This topic is 1782 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I would like my users to input the time in the format HHMM (ie, just numbers, without any delimeter), and it should automatically convert it to correct time format. I have experimented a bit with this, but can't get it to work 100%. 

Eg; with the below calculation it works for all times after noon. Ie, "1215" converts it correctly to 12:15, but "0830" will not (it will be converted to "83:00").

Let ( $Timein = GetAsText ( indata ) ; 
Time ( Left ( $Timein ; 2 ) ; Middle ( $Timein ; 3; 2 ) ; "00" ) 
)

 

Is there anyone that already have done this satisfactory? 

Link to comment
Share on other sites

What do you want to see if it’s 12:15am, and how should it be entered?

Are you counting on the user to correctly enter 0015?

Maybe double pop ups, tied to value lists-one for hours, one for minutes.

Edited by Steve Martino
Link to comment
Share on other sites

1215am should be seen as 00:15 (because we use 24h format in Sweden where I am).

Yes, the user will enter 0015 as the input data. No more, no less. ;) 

 

Link to comment
Share on other sites

This works for me:

Let (
[TimeEntered = Get ( ActiveFieldContents );
TimeCalc = Right("0000" & Filter ( TimeEntered ; "0123456789" );4)];

Left (TimeCalc; 2 ) & ":" & Right ( TimeCalc ; 2 )

 )

Edited by Fran_g
added info - used as script trigger OnObjectValidate
Link to comment
Share on other sites

I would use two fields for this:

  • TimeEntry (Number)
  • Timefield (Time)

Define Timefield to auto-enter calculated value (replacing existing value) =

Time ( Div ( TimeEntry ; 100 ) ; Mod ( TimeEntry ; 100 ) ; 0 )

On the layout, place TimeEntry behind Timefield and make Timefield non-enterable.

Link to comment
Share on other sites

3 hours ago, Fran_g said:

This works for me:

it did not work for me. I see now that you have added that it needs to be entered via a script trigger. This could work, but there is a problem: suppose user enters "1245". This is correctly converted to time 12:45:00 and displayed as 12:45. Now if user clicks into the field and corrects the entry to 12:50:00, the result will be time 50:00:00. I believe this could be fixed (as well as simplified a bit) by making the script set the time field to =

Let ( [
entry = Get ( ActiveFieldContents ) ;
n = Filter ( entry ; "0123456789" )
] ;
If ( 
PatternCount ( entry ; ":" ) ; entry ;
Time ( Div ( n ; 100 ) ; Mod ( n ; 100 ) ; 0 )
)
)

 

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

It still works for me - I don't have the problem you describe  (FM version 11; Windows 7).

The field is set to select entire contents on entry and formatted to show 12 hour format with AM and PM

As you note, I edited the post to add the  information I forgot to put in the orginal reply about the field having a script trigger attached.

 

Link to comment
Share on other sites

On 6/6/2019 at 7:18 AM, Fran_g said:

This works for me:

Let (
[TimeEntered = Get ( ActiveFieldContents );
TimeCalc = Right("0000" & Filter ( TimeEntered ; "0123456789" );4)];

Left (TimeCalc; 2 ) & ":" & Right ( TimeCalc ; 2 )

 )

Are you sure?

Because when I enter "2030" gives the output "2030:00:00"... 🤔

On 6/6/2019 at 10:02 AM, comment said:

I would use two fields for this:

  • TimeEntry (Number)
  • Timefield (Time)

Define Timefield to auto-enter calculated value (replacing existing value) =


Time ( Div ( TimeEntry ; 100 ) ; Mod ( TimeEntry ; 100 ) ; 0 )

On the layout, place TimeEntry behind Timefield and make Timefield non-enterable.

 

If two fields are needed, then I have to use two fields. I would of course rather only have one field, but I have also thought that this maybe would be necessary...

On 6/5/2019 at 9:20 PM, Steve Martino said:

 

Still, these are time pickers. I would rather just use a simple input field with four numbers, that is converted to a correct time.

Link to comment
Share on other sites

This topic is 1782 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.