-
safetycoursesAsked on May 23, 2025 at 1:58 PM
My form has a date field that collects the time as well, and I would like to update a different field based on the hour of the day that was selected. In this case I have an am/pm checkbox that I need to fill and I'd like to update the value of that checkbox by calculating if the hour selected in the date field was greater than noon. I need this to be a separate field and not just to display in the date field as "1:30 p.m." for example, because of how this is being transferred to the Smart PDF.
When I try to run a calculation on the date field using the function hours(DateField) it returns a long number that increments up by 2500 every minute, instead of returning a number 0-24 representing the hour of the time selected.
I was able to jerry-rig it to work (almost) by making a separate field of just time which is automatically filled by copying the value from the date field when the date field is filled, and then using conditional logic on the separate time field to look for if it is greater than 12:00. However this fails when the time selected is between 00:00-00:59 (12:00-12:59 am we use 24 hour time in our organization), any time in this range is copied over to the time field as 12:00-12:59 (12:00-12:59 pm).
See examples below:
This is 12:35 pm and copies over correctly as 12:35 pm
This is 1:35 am and copies over correctly as 1:35 am
This is 12:35 am and copies over incorrectly as 12:35 pm
-
Keenly JotForm SupportReplied on May 23, 2025 at 2:14 PM
Hi safetycourses,
Thanks for reaching out to Jotform Support. I'll need a bit of time to look into this. I'll get back to you as soon as I can.
Thanks for your patience, we appreciate it.
-
Keenly JotForm SupportReplied on May 25, 2025 at 3:35 PM
Hi safetycourses,
Instead of using conditional checks like before 12:00 or after 11:59 to identify whether a selected time falls under AM or PM, it’s more reliable to use the Form Calculation widget, which gives us numerical value of the time input. This value increases consistently from 00:00 up to 23:59, making it a solid basis for comparison.
The Form Calculation widget generates steadily increasing numerical values as time progresses. For instance, 00:00 gives 72841200000, 11:59 gives 72842997500, and 12:00 gives 72843000000. This continuous rise lets us treat time as a consistently growing number throughout the day, making conditional logic more accurate and reliable.
From this, we can observe two key things:
- The value increases steadily as time progresses throughout the day
- The exact dividing line between AM and PM occurs at 72843000000, which represents 12:00 PM (noon). So, any value less than 72843000000 is AM, and any value equal to or greater than 72843000000 is PM.
This method is far more precise and reliable than checking formatted times like before 12:00, which often fail during early morning hours (00:00 to 00:59). To set up these conditions in your form, let me walk you through the steps:
First, let's go to the condition setup of the AM/PM fields and change them accordingly.
1. In Form Builder, select the AM/PM field and click the Conditions button to open Conditions page.
2. In the Conditions page that directly affects the AM/PM field, hover over the condition that determines whether the time falls under AM, and click the gear button to open the condition setup.
3. In the Condition setup for determining AM, update the logic rule to check if the time value is less than 72843000000 (12:00 PM), as you see below, and click Save.
4. While still in the Conditions page that directly affects the AM/PM field, hover over the condition that determines whether the time falls under PM, and click the gear button to open the condition setup.
5. In the Condition setup for determining PM, update the logic rule to check if the time value is greater than 72842999999 (before 12:00 PM), as you see below, and click Save.
With this setup, your AM/PM conditions will work more accurately and consistently, especially when distinguishing between AM and PM. Check out the screencast showing how the form behaves with new conditions in place.
That's it. Give it a try, and let us know how it goes.
-
safetycoursesReplied on May 25, 2025 at 4:17 PM
Thank you for this detailed explanation. Trying it now as you described does not indeed work to solve my problem. The numerical value 72843000000 is equal to midnight (00:00) specifically of 5/26/2025 . The value presented in the calculation field is taking into account the date as well as the time and is different for every date selected even showing the same time. Im not sure if there is also a time zone element playing into it as well as I am in the EDT timezone.
What I observe is that this numerical value displayed is valuing each minute at 2500 and starting from Unix epoch 01/01/1970. So a value of 0 would be midnight on 1/1/70, and in it goes up from there consistently by 2500 every minute.
What I don't understand is why each minute is worth a 2500 increment?
What appears to be a bug is that using the "hours()" function in the calculation field is supposed to return a value indicative of the hour of the day, regardless of the date. The numerical value should reset to 0 for each new day at midnight when using this function, however that is not how it is behaving.
A second bug appears to be that calculating the time value out of a date field into a time field automatically gets the time wrong for times between 00:00-00:59, they instead copy as 12:00-12:59.
-
Eliza JotForm SupportReplied on May 25, 2025 at 4:57 PM
Hi safetycourses,
I understand what you’d like to do, but I’ll need a bit of time to work out a solution. I’ll get back to you shortly.
Thanks for your patience, we appreciate it.
-
Eliza JotForm SupportReplied on May 25, 2025 at 8:08 PM
Hi safetycourses,
I've tried multiple workarounds, but the one I can suggest, which I believe works on what you need in terms of mapping to your original PDF, is to enable the AM/PM option on the Date Picker's Time feature. Then, we can update the conditions you have, as well as the formula in your Form Calculation widget. Let me walk you through it step-by-step:
1. In Form Builder, click on the Date Picker element, labeled as Report Date, and select the Gear icon.
2. On the Date Picker Properties panel, go to the Time tab, and select AM/PM under Time Format.
3. Once done, click on the Form Calculation widget, and select the Wand icon to open the Form Calculation Properties panel.
4. Remove the formula that you have, and click on the Add Field button.
5. Select the Date Picker field from the options, and change 0-9 to A-Z, which means String.
6. Click on Save. You can also hide the field if you want.
Now, let's update the conditions for the Multiple Choice field you have, labeled as AM/PM:
1. Click on the AM/PM field, and select the Conditions icon.
2. Hover your mouse over the first conditions template, and click on the Pencil icon to edit it.
3. Update the conditions to look like the one in the screenshot below, and click on Save at the bottom.
4. Hover your mouse over the second conditions template, and click on the Pencil icon.
Check out the screencast below to see my results:
Give it a try and let us know if you need any other help.
-
safetycoursesReplied on May 26, 2025 at 1:33 AM
Hi Eliza,
Thank you for this workaround. I did try it, and it reliably check off the AM PM check boxes on my PDF, but it also prints the text ("AM/PM") in the time field box which is now redundant and does not belong there. Is there a way for it to not print the AM PM while still giving me the data to check the boxes?
-
Ronald JotForm SupportReplied on May 26, 2025 at 2:25 AM
Hi safetycourses,
You can pass in the value of the Report Date field to a Short Text field that has a masking option. This will remove the AM/PM field from being passed to the Short Text field. It is very easy to do. Let me show you how:
1. Add a Short Text field to your form and click the Gear icon.
2. Under the Options tab, toggle on the Input Mask option.
3. Add the Value: **/**/**** **:**
You can then setup a condition to pass the value of the Report Date field to a Short Text field. See the screenshot below:
Lastly, add the Short Text field in the PDF instead of the Report Date field.
See the screenshot below for the results of the PDF file:
Reach out again if you need any more help.
-
safetycoursesReplied on May 26, 2025 at 12:31 PM
Hi Ronald,
I tried what you suggested, but it does not work. As you can even see in the screenshot of the PDF you provided in your answer, the Time field on the PDF is filled with the Date instead of showing the time.
I tried adjusting the mask to only "##:##" but then it used the first four digits of the date to fill in the TIme field e.g "05:26", and not display the actual time either.
I was able to figure a very clunky workaround here building on the different elements suggested here to finally get something that works. It requires the use of 5 separate fields with calculation logic for all of them.
- When Report Date is filled, copy timestring value into Report Time Calculation field
- IF Report Time Calculation field contains "AM", copy "AM" value into AM/PM checkbox
- IF Report Time Calculation field contains "PM", copy "PM" value into AM/PM checkbox
- Set up the Substring using the Field ID "#input_67_timeInput" of Report Date to only extract the Time Input. (This results in filling only the time "12:11" without the am/pm string in the Substring field.
- When Substring is filled, copy Substring value (just the time string) into Report Time Print.
- On the PDF add the Report Time Print field, and the AM/PM checkbox field.
-
Adrian Besilla JotForm SupportReplied on May 26, 2025 at 12:54 PM
Hi safetycourses,
Thank you for the detailed follow-up, and we’re glad to hear you were able to come up with a workaround that gets the result you need. We appreciate you sharing the steps you took that our team can also review for further improvements.
Note that the DateTime field can be tricky when it comes to isolating and displaying just the time value in the PDF. By default, the PDF builder tends to treat the DateTime field as a full timestamp, which can lead to unexpected formatting, especially when you're only interested in displaying the time. While adjusting the input mask or format in the field settings helps in the form itself, it doesn’t always reflect accurately in the generated PDF, which is something we’ve raised with our development team.
That said, does your current setup fully resolve the issue on your end, or are there still parts of that you'd like help streamlining?
Let us know if there's anything else we can help you with.
-
safetycoursesReplied on May 26, 2025 at 1:35 PM
The current setup allows the PDF to print correctly.
Ideally I was hoping to be able to input the time into the form using 24 hr time format, as that is what our field users are accustomed to with all our other forms. However with the malfunctioning calculation functions (namely the hours() function not returning the hour selected as it should), and the copy function getting confused with times between 12:00-12:59 am as demonstrated above, this doesn't seem possible until those bugs get fixed.
Your Reply
Something Went Wrong
An error occurred while generating the AI response. Please try again!