2 Replies Latest reply on May 8, 2011 1:48 AM by FMNewbie

# Convert 4-digit number to time?

### Title

Convert 4-digit number to time?

### Post

FMPro 11, Mac OS

Is there a way to turn a 4-digit number into a time without having to type a colon between the hrs and mins??  i.e., the user would enter 1234 and it would be converted to 12:34?? I'm probably missing some very simple answer.

Thanks.

• ###### 1. Re: Convert 4-digit number to time?

A generic basic solution would be to add an auto-enter to the TIME field (uncheck at auto-enter tab 'do not replace existing values if any' and calc might be:

Let ( [
h = Left ( Self ; Length ( Self ) - 2 ) ;
m = Right ( Self ; 2 )
];
Time ( h ; m ; 0 )
)

This would allow Users to enter 3 numbers as well as 4 but it will assume the entry is military time.  If they enter 234, system cannot determine whether they mean 2AM or 2PM.  Being a time field, it will automatically prohibit spaces, carriage returns and alpha characters.  FM will apply its own validation (below basic validations) to fields which are time, date and timestamp so that helps us here.  If you leave the field as text, you would have to jump through hoops to protect and convert the entry so leave it as time if possible.

Note that they MUST enter full minutes otherwise system would not know whether 12 is 12 hours or 12 minutes.  We could add another protection that the value be at least 3 characters and now that I think of it, it might be good idea so it could be modified as:

Let ( [
h = Left ( Self ; Length ( Self ) - 2 ) ;
m = Right ( Self ; 2 )
];
Case ( Length (h&m) > 2 ; Time ( h ; m ; 0 )
) // END CASE
)// END LET

This will simply remove their entry if less than 3 characters.  You might want to use validation instead; there are several ways to go for protecting this field but it would only take a User one time, after being told to enter full minutes, why it blanks out.

• ###### 2. Re: Convert 4-digit number to time?

Sweet.... thank you!!  That works perfectly.