ppbb123 Posted June 4, 2013 Report Share Posted June 4, 2013 How to calculate age and save it in the submission form? I have a Date/Time field which is "Birthday", and another Text field which is "Age" in my table. Thanks Quote Link to comment Share on other sites More sharing options...
HongTaiLang Posted June 4, 2013 Report Share Posted June 4, 2013 You can insert the following in the Footer to calculated the age, and assign the value to the "Age" field after submitting: <SCRIPT LANGUAGE="JavaScript"> function ageCalculate() { //get current date var stamp = new Date(); //get Birthday. change "InsertRecordBirthday" if the fieldname is different var insertDate = document.getElementById('InsertRecordBirthday').value; var birth = new Date(insertDate); //calculation difference = stamp - birth; age = Math.floor(difference / (1000 * 60 * 60 * 24 * 365.25)); //assign it to Age field document.getElementById('InsertRecordAge').value = age; } document.getElementById("caspioform").onsubmit=ageCalculate; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Mustafa007 Posted June 17, 2013 Report Share Posted June 17, 2013 Thank you for the help. I was successfully able to implement your code into my DataPage. Quote Link to comment Share on other sites More sharing options...
cheonsa Posted October 24, 2018 Report Share Posted October 24, 2018 Hi, The Calculated Value form element generates dynamic calculations that automatically update as users interact with your form is now available in the current platform of Caspio. You can calculate the age of a person automatically without submitting the form and without custom programming. You can construct the calculation using functions, logic, constants, values from other fields and SQL expressions. You can refer to these links: https://howto.caspio.com/datapages/datapage-components/calculated-values/ https://howto.caspio.com/function-reference/ Regards, kristina Quote Link to comment Share on other sites More sharing options...
cheonsa Posted May 12, 2019 Report Share Posted May 12, 2019 Hi @ppbb123, I have a formula that gets the exact age considering the leap year. You may visit this link for more details: You may use this in your Calculated Value. Hope this helps. -kristina Quote Link to comment Share on other sites More sharing options...
Kurumi Posted June 24, 2022 Report Share Posted June 24, 2022 Hi - Just an update on this, you may also use these formulas to know the exact age by day: DATEDIFF(hour,[@field:Birthday],SysDateTime())/8766 FLOOR(DATEDIFF(DAY, [@field:Birthday], SysDateTime()) / 365.25) Quote Link to comment Share on other sites More sharing options...
Kurumi Posted 14 hours ago Report Share Posted 14 hours ago Hi! Caspio now offers integration with OpenAI, so you can use extensions to leverage AI to update your data based on a prompt. Here's a sample use case to get the exact age based on the provided birthday(date/time). Request: Calculate the age of someone born on "[@field:Birthday]" as of today. Leave it blank if there is no value in "[@field:Birthday]" Return only the final result as a number. Result: Change the 'Birthday' field to your right field name. To learn more about Extensions, you can check it here: https://howto.caspio.com/integration/extensions/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.