To create a script that calculates a user's age based on their date of birth, follow these steps.
Add a block to the previously created script Question. In this block, the user will be asked for his date of birth.
Add a block The expression.
Enter in the block parameters The expression is as follows:
`$age = dt.sub(@today, $birthDate)`
`$age = $age \ 31511000`
Where:
@today is the current date.
$birthDate is the date of birth of the user.
dt.sub is a date subtraction function.
31553280 is the number of seconds in one year.
Swipe out of the block Question arrow to the block The expression.
Enter the text of the question in the Message field. For example, "Enter your date of birth.".
In the properties of the page, select the output data type — Date.
In the Variable name field, enter birthDate to save the user's response.
Add the Information block.
Connect the block with an arrow The expression with the block Information.
Enter the text in the Message field using the variables:
Your date of birth: {birthDate}
Your age: {age} years
Where:
{bitrthDate} — the user's date of birth is stored.
{age} — the age is stored.
Save and test the script.