To create a script that calculates the user's age based on their date of birth, follow these steps.
Add a Question block to the previously created script. In this block, the user will be asked for their date of birth.
Add an Expression block.
Enter the following in the parameters of the Expression block:
$age = dt.sub(@today, $birthDate)
$age = $age \ 31553280
Where:
@today — the current date.$birthDate — the user's date of birth.dt.sub — the date subtraction function.31553280 — the number of seconds in a year.Draw an arrow from the Question block to the Expression block.
Enter the text of the question in the Message field. For example, “Enter your date of birth.”
In the properties of the middle block, select the output data type — Date.
In the Variable name field, enter birthDate to save the user's answer.
Add an Information block.
Connect the Expression block to the Information block with an arrow.
Enter the text in the Message field using variables:
Your date of birth: {birthDate}
Your age: {age} years old
Where:
{birthDate} — the user's date of birth.
{age} — the user's age.