function declination(a5, b1, c2, s) { 
 	var words = [a5, b1, c2]; 
	var index = s % 100; 
	if (index >=11 && index <= 14) { index = 0; } 
	else { index = (index %= 10) < 5 ? (index > 2 ? 2 : index): 0; } 
	return(words[index]); 
} 

declination('лет', 'год', 'года', 23)

php

function declination($status= array('','а','ов'), $value){
	$array =array(2,0,1,1,1,2);
	return $status[($value%100>4 && $value%100<20)? 2 : $array[($value%10<5)?$value%10:5]];
	}

Bitrix

use Bitrix\Main\Grid\Declension;
$yearDeclension = new Declension('год', 'года', 'лет');
$yearDeclension->get($year);