How to Calculate age between two dates fields

  • JKA_BRASIL
    Perguntado em 6 de junho de 2024 às 14:59

    no form https://www.jotform.com/build/241574990151661, porque a funcao =DATETIME_DIFF descrita em https://www.jotform.com/help/tables-advanced-formula-date-functions/#datetime_diff nao funciona?? Como posso corrigir? How to Calculate age between two dates fields Image 1 Screenshot 20

  • Mike_G Jotform Support
    Respondido em 6 de junho de 2024 às 15:31

    Hi JKA_BRASIL,

    Thanks for reaching out to us for help. I’m sorry you're having difficulties with this. I’ll do my best to help you. I checked the form and it currently does not have any form submissions. Can you explain a bit more about the output or result you are looking to get, so I can get a better idea of what you want to do?

    Once we hear back from you, we'll be able to help you with this.

  • JKA_BRASIL
    Respondido em 6 de junho de 2024 às 15:44

    Hi Mike,

    The issue I'm encountering is with the DATETIME_DIFF(date1, date2[, unit]) function as described in this documentation(https://www.jotform.com/help/tables-advanced-formula-date-functions/#datetime_diff). The function doesn't work, or I might be making a mistake. I have provided an example and created a simpler form in https://www.jotform.com/build/241575868618068#preview, but it still doesn't work.


    Thanks

  • Danilo Jotform Support
    Respondido em 6 de junho de 2024 às 16:11

    Hi JKA_BRASIL,

    Thanks for getting back to us. I just wanted to confirm if you're trying to calculate the two date fields on Tables. If yes, you can achieve this by setting up two Date fields, using the Form Calculation widget and conditions to show or hide the fields based on the calculated value. Let me show you how:

    1. Add two Date Picker fields to your form.
    2. Set the first Date Picker field as Current and the second as the Date of Birth field.How to Calculate age between two dates fields Image 1 Screenshot 40
    3. Next, add the Form Calculation widget to perform calculations for age.How to Calculate age between two dates fields Image 2 Screenshot 51
    4. Set the calculation for the Form Calculation widget, as shown below:
    5. floor((Current Date - Date of Birth) / 365)

    Check out the screencast below of my clone form, you're free to clone it using this guide.

    How to Calculate age between two dates fields Image 3 Screenshot 62

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

  • JKA_BRASIL
    Respondido em 6 de junho de 2024 às 18:18

    thank you