How to calculate number of hours?

  • Bioanalise
    Perguntado em 1 de agosto de 2023 às 06:04

    Ola.
    Estou precisando fazer formulário para calcular a diferença de entre duas datas
    Ja fiz varias pesquisas e não descobri.
    Exemplo:

    Início: 01/08/2023 08:00
    Fim: 01/08/2023 09:00

    Preciso calcular a quantidade horas entre as datas.

    Segue print do formulário em questão

    How to calculate number of hours? Image 1 Screenshot 30How to calculate number of hours? Image 2 Screenshot 41

  • Joshua_T Jotform Support
    Respondido em 1 de agosto de 2023 às 11:34

    Hi Bioanalise,

    Thanks for reaching out to Jotform Support. Unfortunately, our Portuguese Support agents are busy helping other Jotform users at the moment. I'll try to help you in English using Google Translate, but you can reply in whichever language you feel comfortable using. Or, if you'd rather have support in Portuguese, let us know and we can have them do that. But, keep in mind that you'd have to wait until they're available again.

    Now, let me help you with your question. I am sorry you are having trouble with this. Yes, it is possible to calculate the number of hours worked per day. But, we can do this if the hours are in 24 hours format. Let me show you how:

    1. First, set your time in your Date Picker element to 24Hours format.How to calculate number of hours? Image 1 Screenshot 60
    2. Next, add a Substring Widget to extract the Hours from the Date Picker element.How to calculate number of hours? Image 2 Screenshot 71
    3. Then, add this condition:How to calculate number of hours? Image 3 Screenshot 82

    Here's the result:

    How to calculate number of hours? Image 4 Screenshot 93

    You can also hide the Substring Widget:

    How to calculate number of hours? Image 5 Screenshot 104

    If you want to clone this Demo Form for testing, you can do so. Let me show you how:

    1. First, copy the URL of the form that you want to clone.
    2. Then, go to My Forms and select Create Form in the upper-left corner.
    3. Next, click on Import Form and select From a Web page and then paste the Form URL of the form you want to clone in the URL field.
    4. Lastly, click on Create Form. That's it.

    How to Clone a Form? Image 1 Screenshot 20 Screenshot 115

    Give it a try and let us know how it goes.

  • Bioanalise
    Respondido em 3 de agosto de 2023 às 08:42

    Very good, I managed to complete 90%, but my result of total hours is showing a value with two decimal places. that is, instead of displaying a number with one unit, it is displaying two decimal places. What type of field did you use to fill in the total hours? Or how do I make it show me only a maximum of two decimal places?

  • Annaliza_O Jotform Support
    Respondido em 3 de agosto de 2023 às 10:58

    Hi Bioanalise,

    Thanks for getting back to us. For the total hours, my colleague use a short text widget and then add a conditional logic to get the total number of hours.
    How to calculate number of hours? Image 1 Screenshot 20

    Here's the demo form. Feel free to clone the form to test and check the settings. Reach out again if you have any other questions.