חישוב גיל מתאריך לידה: הבדלים בין גרסאות בדף
קפיצה לניווט
קפיצה לחיפוש
(הוספת דף חישוב גיל מתאריך לידה) |
|||
| שורה 37: | שורה 37: | ||
<syntaxhighlight lang="javascript" line="1"> | <syntaxhighlight lang="javascript" line="1"> | ||
if(data[' | if(data['birthday'].trim()===''){return 0;} | ||
const birthdate = new Date(data[' | const birthdate = new Date(data['birthday']); | ||
const currentDate = new Date(); | const currentDate = new Date(); | ||
const currentYear = currentDate.getFullYear(); | const currentYear = currentDate.getFullYear(); | ||
גרסה מ־15:54, 11 באוגוסט 2025
כדי לחשב גיל משדה תאריך לידה, יש להגדיר את הפעולות הבאות:
בדף עריכת הטופס, עבור שדה הגיל, יש ללחוץ גלגל השיניים וללכת ללשונית "הגיון".
יש ללחוץ על "הוספת לוגיקה"
יש לתת שם ללוגיקה ולהוסיף פעולה באמצעות "הוספת פעולה".
יש למלא את הפרטים עבור הפעולה, ולהכניס את הקוד הבא באיזור הערך (Javascript):
if(data['birthday'].trim()===''){return 0;}
const birthdate = new Date(data['birthday']);
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const birthYear = birthdate.getFullYear();
const currentMonth = currentDate.getMonth();
const birthMonth = birthdate.getMonth();
const currentDay = currentDate.getDate();
const birthDay = birthdate.getDate();
var age = currentYear - birthYear;
if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
age--;
}
return age || 0;