Подскажите пожалуйста содержание скрипт где можно написав дату в поле "Дата рождения" в поле "Количество полных лет" показать цифру. Заранее благодарю.
Рассчитать в соседнем поле количество полных лет
Collapse
X
-
В хелпе написано: datetime\diff
datetime\diff(VALUE_1, VALUE_2, INTERVAL_TYPE) Returns difference between two dates or datetimes. INTERVAL_TYPE can be 'years', 'months', 'days', 'hours', 'minutes'. Returns null if failure. Result will be negative if VALUE_1 < VALUE_2.
имя_поля_кол-во_лет = datetime\diff(datetime\today(), имя_поля_с_др, 'years'); -
Здравствуйте.
Тут в украинской ветке форума этот вопрос поднимался https://forum.espocrm.com/forum/inte...B0%D0%BA%D1%82. Я надеюсь что с переводом проблем не будет. Там как раз описан процесс высчета полных лет. Просмотрите топик до конца так как там вносились изменения в формулу что бы она корректно высчитывала возраст.Comment
-
ifThenElse(
datetime\month(datetime\today()) >= datetime\month(dateofbirthday) &&
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) - 1
);
ifThenElse(
datetime\month(datetime\today()) == datetime\month(dateofbirthday),
ifThenElse(
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
month = 0,
month = 12
),
ifThenElse(
(datetime\month(datetime\today()) - datetime\month(dateofbirthday)) < 0,
month = (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) + 12,
month = 0 + (datetime\month(datetime\today()) - datetime\month(dateofbirthday))
)
);
Подскажите пожалуйста а что из них название полей?Comment
-
ifThenElse(
datetime\month(datetime\today()) >= datetime\month(dateofbirthday) &&
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) - 1
);
ifThenElse(
datetime\month(datetime\today()) == datetime\month(dateofbirthday),
ifThenElse(
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
month = 0,
month = 12
),
ifThenElse(
(datetime\month(datetime\today()) - datetime\month(dateofbirthday)) < 0,
month = (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) + 12,
month = 0 + (datetime\month(datetime\today()) - datetime\month(dateofbirthday))
)
);
Comment
-
Замените первый блок ifThenElse на
Code:ifThenElse( datetime\month(datetime\today()) > datetime\month(birthday) || datetime\month(datetime\today()) = datetime\month(birthday) && datetime\date(datetime\today()) >= datetime\date(birthday), age = (datetime\year(datetime\today()) - datetime\year(birthday)), age = (datetime\year(datetime\today()) - datetime\year(birthday)) - 1 );
Comment
-
Всё равно на дату 30.04.1988 показывает 30 лет. Должно быть 31
ifThenElse(
datetime\month(datetime\today()) > datetime\month(dateofbirthday) ||
datetime\month(datetime\today()) = datetime\month(dateofbirthday) &&
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) - 1
);
ifThenElse(
datetime\month(datetime\today()) == datetime\month(dateofbirthday),
ifThenElse(
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
month = 0,
month = 12
),
ifThenElse(
(datetime\month(datetime\today()) - datetime\month(dateofbirthday)) < 0,
month = (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) + 12,
month = 0 + (datetime\month(datetime\today()) - datetime\month(dateofbirthday))
)
);
ifThenElse(
datetime\month(datetime\today()) > datetime\month(dateofbirthday) ||
datetime\month(datetime\today()) = datetime\month(dateofbirthday) &&
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)),
age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) - 1
);
ifThenElse(
datetime\month(datetime\today()) == datetime\month(dateofbirthday),
ifThenElse(
datetime\date(datetime\today()) >= datetime\date(dateofbirthday),
month = 0,
month = 12
),
ifThenElse(
(datetime\month(datetime\today()) - datetime\month(dateofbirthday)) < 0,
month = (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) + 12,
month = 0 + (datetime\month(datetime\today()) - datetime\month(dateofbirthday))
)
);
Comment
-
Хах. Действительно проблемка. После последнего исправления я тестировал только в рамках одного месяца и проблема не была мною замечена. Я подправил. Теперь ,блок по расчету возраста выглядит так:
Code:age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) - 1; ifThen( datetime\month(datetime\today()) > datetime\month(dateofbirthday), age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) ); ifThen( datetime\month(datetime\today()) = datetime\month(dateofbirthday) && datetime\date(datetime\today()) >= datetime\date(dateofbirthday), age = (datetime\year(datetime\today()) - datetime\year(dateofbirthday)) );
Code:ifThenElse( datetime\month(datetime\today()) == datetime\month(dateofbirthday), ifThenElse( datetime\date(datetime\today()) >= datetime\date(dateofbirthday), month = 0, month = 12 ), ifThenElse( (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) < 0, month = (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) + 12, month = 0 + (datetime\month(datetime\today()) - datetime\month(dateofbirthday)) ) );
Comment
Comment