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.


  • Profile Image

    How is date-time math performed?

    Asked by emgh3i on September 13, 2015 at 04:01 AM

    I want to calculate a field value based on whether the form was submitted within a certain time interval.  I charge prices for services based on when they are requested relative to when the services are needed.  For example, if a request (submission) is made less than 48 hours in advance of the services being needed, I charge $20...if the submission is made at least 48 hours in advance of the services being needed, I charge $15...if the submission is made at least 72 hours in advance of when the services are needed, I charge $10.

    Therefore, I want to do something like:

    if ({submission date & time} is after {{requested service date & time} - 48 hours} then set total_field to $20)

    elseif ({submission date & time} is before or equal to {{requested service date & time} - 48 hours} and {submission date & time} is after {{requested service date & time} - 72 hours}) then set total_field to $15

    else set total_field to $10

     

    -----------------------------

    NOTES:

    1) This total_field would be passed to PayPal so that the user can pay the proper amount.

    2) submission date & time = timestamp applied by JotForm to the submission

     

    3) requested service date & time = input from user into a date-time field

    math date-time prices charge time field calculation conditio
  • Profile Image
    JotForm Support

    Answered by jonathan on September 13, 2015 at 07:35 PM

    Can you please test this demo form http://form.jotformpro.com/form/52557605632962?

    From what I understand, the very 1st requirement is to determine the how many days before the Submission Date the request was made.

    #1. Add 2 DateTime field 

       a) SubmissionDate  - timestamp. This is read-only and determines when the end-user submitted the form.

       b) RequestedDate - end-user input (date of request service)

     

    #2. Calculate the No of Days difference bet the RequestDate and actual form Submission Date

    #3 Using Calculate Condition Logic, calculate the charge amount (Sub-Total)

     

    #4 Pass the Sub-Total value to Paypal Amount value for payment.

     

    For the purpose of demo only, the appropriate fields were not hidden on the Form. They can be hidden using the Form Builder.

    Please check the form and let us know if it matches the payment calcuation base on date you were looking for. Let us know if you need further assistance.

     

     

  • Profile Image

    Answered by emgh3i on September 13, 2015 at 11:15 PM

    Thanks for the quick response.  What you showed above is maybe the best that I can do but what I was really after to to calculate hours, not days.  In other words, if game time is 9/15/15 4:00pm PT and submission time is 9/13/15 4:01pm PT I want to charge the highest rate ($20) but if submission time is 9/13/15 4:00pm PT, then I would charge the next lowest rate of $15 because the submission was made exactly 48 hours in advance of game time.  Is there any way to incorporate the time element in the calculations?

  • Profile Image
    JotForm Support

    Answered by Charlie on September 14, 2015 at 11:06 AM

    Hi,

    I'm not sure if I understand your requirements based from the first post and the last post you have.

    Could you share us more simpler condition?

    If I am not mistaken, you have two dates here, the "Game Date & Time" and the "Submission Date & Time". I'm not sure about the "Requested Service Date & Time"?

    If the basis of the charge is how early they purchase a ticket, this is how I am understanding it.

    IF (Game date&time - Submission date & time) is more than 3 days/72 hours THEN charge the user $10

    IF (Game date&time - Submission date & time) is more than 2 days/48 hours BUT is less than 3 days/72 hours THEN charge the user $15

    IF (Game date&time - Submission date & time) is less than 2 days/48 hours THEN charge the user $20

     

    Which means, the earlier or the farther the date, the lesser the charge will be. Here's an example form that I made: http://form.jotformpro.com/form/52563976630968?. See if that works as you expected. You can clone it using this guide: https://www.jotform.com/help/42-How-to-Clone-an-Existing-Form-from-a-URL. You can still use the calculation of my colleague, "NoofDays" more than 48hrs will be 2.01 and so on.

    I hope that helps.

  • Profile Image

    Answered by emgh3i on September 15, 2015 at 01:41 AM

    Almost there but "NoofDays" appears to calculate an integer rather than a decimal.  Since I need to be able to distinguish 48 hours from 48 hrs and 1 minute, the calculation needs to take into account the submission date *and* time and the game date *and* time.  It appears that the calculation for "NoofDays" is only taking the date into account and ignoring the time.  Is that true?  If not, how can I evaluate "NoofDays" as a decimal with precision to at least the tenths place?

  • Profile Image
    JotForm Support

    Answered by Charlie on September 15, 2015 at 05:17 AM

    Hi,

    I'm not sure if it is possible to do that using the available features.

    But, you can easily increase the decimal places of "NoofDays" to see the smallest difference that the two dates have in terms of minutes.

    So basically, 1 minute is equal to 0.00069 here.

    You can check the updated form here: http://form.jotformpro.com/form/52563976630968? 

     

    To make it accurate, I made sure that the "Game Date & Time" and the "Submission Date" has minute stepping of "1".

    To do that, just navigate to the "Date" fields properties and set the "Minute Stepping" to a smaller value, to have a more accurate selection.

     

    You can now test my form, you'll see that because the decimal places has now increased, the difference in minutes can already be seen.

    Although, the problem on this is that the difference of 1 minute in the calculation has a very lengthy decimal value. See if increasing the decimal places around 10 would give you the most exact value. 

    I hope this helps.

  • Profile Image

    Answered by emgh3i on October 13, 2015 at 10:06 PM

    I finally got back around to this.  I just have one more question.  

    How do I add that read-only submission date field to my existing form?
  • Profile Image
    JotForm Support

    Answered by jonathan on October 13, 2015 at 11:17 PM

    We will answer your next question separately here http://www.jotform.com/answers/680877

    Thanks.