What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.
At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.
We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.
Format Time Calculation output to render in 12hr AM/PMAsked by MaidCrew on December 29, 2015 at 06:33 PM
Hello... I've created a simple form designed to provide an estimated job completion time based on:
PRICE divided by HOURLY RATE divided by #WORKERS = Amt of Time Team is to provide.
(Ex: $140 / $35 = 4 hours / 3 workers = 1.33 hours of time)
I also show a "Current Time" field on the form.
I have a form calculation in which I ADD "Current Time" + "Amt of Time Team is to provide (1.33)"
I'm left with an output of 24hr time rendering as a decimal.
Is there a way to convert the output to render the as 12 hour AM/PM equivalent?
[ Desired Outcome ... If the current time is "2:00 PM" and "Amt of time Team is to provide" is 1.33 (1 hr 20 mins), I want to be able to explicitly tell the team that they must be finished and leave the job by 3:20 PM ]
Thanks in advance :-)
That seems challenging. Let's see if we can find a workaround for that in the form builder. We'll get back to you with updates. Stay tuned! :)
Here's my version https://form.jotform.com/53631433043951
Unfortunately, I could not find a solution to split the decimal points (within the form builder) so I decided to round the decimal value by changing the decimal places to zero (0) in the calculation wizard.
If you like this solution, please clone this form so you can find out the changes. You should see 2 conditions on this form for (if greater than 12) and (if less than 13). This condition turns the 24-hour format into 12-hour format.
Hope this helps!
Thank you Elton. Are there any additional Support Techs who can take a look and see if they've got any ideas or other work-arounds? Would there be a solution through any other widgets? I really need the output to render both hours & minutes rather than just rounding up or down to the nearest hour. Thanks.
Let me try applying my colleague's cloned form and implement the workaround I have in mind. I'll get back to you as soon as I have it working.
Could you try this form: https://www.jotform.com/53634266070958. I also added a date field to where when the current time passes 12 midnight or the next day it should still show the correct date. You can clone my form to see how it is setup, or I can also list down the steps on how I did mine. Please note that I the fields are not hidden anymore so that it's easier to see how the data flows, you can hide the fields depending on your own preference.
Let me know if that works.
Hey Charlie... this looks good. I'll play around & test it out. I'm very thankful to you & Elton! It's an enormous help & greatly appreciated!
Hi Shawn, I made some edits to improve the logic of the form, mostly focused to the time passing the 24 hour marked. I think it works better now. Please try cloning the form again and see if it works better.
Hey Charlie... still trying to understand the logic behind how you constructed the work-around... I'll get it eventually the more I play around but got a quick question. Is there a way to force the minute to render as minimum of 2 digits (not 2 decimal) because if the time is suppose to be say, 9:08 AM, it renders as 9:8 AM. Any way around that?
I'm continuously making adjustments on my custom form for the flaws and incorrect output. I did not noticed the 2 digit case for the minutes, thank you for pointing it out. It might be because the minute stepping is set to "10" in my case. You can check the most up to date form here: https://form.jotform.com/53634266070958. The minute should now be resolved. The only problem that I am seeing now is that when the time of completion is set to 12 midnight, it does not immediately show the result unless you tab on the other fields. You can clone my form again to see the changes.
To understand how my workaround is setup, here are some information on how I did it:
1. These are the fields that are essential for the workaround.
"Current Time (24 Hour Format)" => Time value is in 24 hour value, that will allow us to easily calculate the hours and minutes. This can be hidden and we can leave the "Current Time" visible to the user. I presume these times are read-only and is set automatically to the "Current" time.
"Amt of time + Current Time (24 Hour Format)" => We had the total time
"Hour" => We will store our hour value here
"Initial Minutes" => We will store our raw minute value here. Raw because the number is an absolute value. Let's say the minutes in 2:03 PM is "03", however, the raw number of it is "3", without "0"
"Converted Minutes" => This is where we will output the minute value that is time format friendly. Example, from 2:3 PM where "3" is the minute value it will because "03".
"You should be finished around ..." => This is the combination of "Hour" and "Converted Minutes" and we will use conditional logic to tell if it is "PM" or "AM".
2. This is how each fields are setup:
"Amt of time + Current Time (24 hour format)" => We will use "Form Calculation" widget here. Using this format:
(("This job will Cost the client..." / 35 ) / "Number of Workers" ) + "Current Time (24 hour format)"
"Hour" => This is quite tricky, we will use form calculation widget BUT we will use conditional logic to assign a value on it. Here are the conditions for the "Hour" format:
Condition 1: IF "Amt of time + Current Time" is less than 25 AND is greater than 23.99 THEN apply the following formula.
(floor ("Amt of time + Current Time") - 24 ) + 12
What it does? It means that when the time of completion is set to 12 midnight of the next day, we will subtract 24 to the amount of time and add 12 on it. Here an example:
IF "Amount of Time + Current Time" is 24.3...
= (floor (24.3) - 24 ) + 12
= (24 - 24) + 12
= (0) + 12
= 12 midnight
The floor function rounds the number downwards. You can check that function in this article: http://www.jotform.com/help/267-Form-Calculation-Math-Function-Reference
With that approach, you can convert the 24 hour format to a 12 hour format.
"Initial Minutes" => We want to get the minutes out of the total time. How do we do this? Here's the formula:
round ( ("Amt of Time + Current Time" - floor ( "Amount of Time + Current Time" )) * 60 )
IF total time is 17.05
= round ( (17.05 - floor ( 17.05 ) ) * 60 )
= round ( (17.05 - 17 ) ) * 60 )
= round ( (0.05) * 60 )
= round ( 3 )
= 3 minutes
The problem is that we cannot use "3" in minutes without having "0" on it, which should be "03". To resolve this, proceed on the "Converted Minutes" below.
"Converted Minutes" => This is a form calculation widget BUT we will use conditional logic to assign its value.
Here are the conditions:
If "Initial Minutes" is greater than 9.99 which means it will be 10 and above, then just output "Initial Minutes" directly to "Converted Minutes"
If "Initial Minutes" is less than 10, which means a single digit, then we will append "0" as a prefix.
3. Now we have our hour and minutes value. How do we output it on our "You should be finished around ... " with an "AM" or "PM" format?
We will used a simple text box in this part.
We will then use conditional logic to combine the hour and minutes value then assign if it's AM or PM.
IF the "Amt of Time + Current Time" is less than 12, which means it is morning in the 24 hour format. Then combine "Hour" : "Converted Minutes" AM to the text box.
IF time is greater than 11.99 AND is less than 24, which means time is from 12 to 23 which is in 24 hour format it is in the afternoon and evening, then add PM as a text.
IF the total time is greater than 23.99 which means 24 onward and is 12 midnight on the next day, then add "AM" on the text.
The only problem I'm seeing now is that if the amount of time need to complete a project reaches more than 36 hours, then you'll need additional conditions to cover those parameters.
I hope this helps. I understand that this might be confusing at first. But if you have questions, feel free to ask.
Awesome Charlie... yes, it'll take me a while to digest but thank you! As for the >36hr limitation, that would never be a problem... its rare if we ever go beyond a 10 hour project/job.
Secondary question though... is there a generally understood limitation on y'alls end on number of conditions a form can have (overall) before the form's functionality begins to degrade / glitch / break?
You are welcome :)
As far as I know, the number of conditions in the form usually affects the overall functionality of the form itself when there are conflicting conditions and errors on how it is setup. I see some users that have 100+ conditions but the form works okay, this is because conditions were setup properly without conflict to one another. The "Conditions" feature is a main part of our form builder and I believe it will not degrade, instead it is continuously being improved.
If there are complex functionality you want to add on the form and the conditions may not be able to handle or recreate them properly, then you can always have the form's full source code, create a custom script for that complex functionality and hard code it to the form's source code.
Do let us know if you need further assistance on this.
Hey Charlie... not sure if you're still in support or are able to help me but I have another question or need. I posted another time conversion question in the support forum. Was wondering if you'd be able to assist again? My support request is titled under:
Converting Decimal # to "# hrs, ## mins" and located under https://form.jotform.com/60875620033148
Thanks in Advance,
As far as I can see, you have already solved the issue per this thread. Please feel free to contact us anytime if you need any further assistance.
Hey Mike, actually, I do need some additional help. I've edited the previous question submitted so it's now titled: Converting / Rounding up or down to nearest 10 min mark.
It can be found at the link: https://form.jotform.com/60875620033148
Thanks in Advance,
I have updated the other thread. Thank you.