p006/api/soft/smarty/3.1.39/libs/plugins/modifier.vozrast.php

22 lines
475 B
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
принимает строку дд.мм.гггг и вычисляет возраст
*/
function smarty_modifier_vozrast($string){
function getAge($y, $m, $d) {
if($m > date('m') || $m == date('m') && $d > date('d'))
return (date('Y') - $y - 1);
else
return (date('Y') - $y);
}
$d=substr($string, 0, 2);
$m=substr($string, 3, 2);
$y=substr($string, 6, 4);
return getAge($y, $m, $d);
}