Вычислите годы с даты

Я не уверен, каков объем Вашего вопроса, но я верю:

isql использовал Библиотеку DB для передачи с сервером и больше не включается после того, как SQL2000

osql использовал ODBC для передачи с сервером, и больше не не будет включенный после того, как SQL2005

sqlcmd использовал OLE DB для передачи с сервером и в настоящее время является рекомендуемым инструментом командной строки.

14
задан Jonathon Watney 11 July 2009 в 03:39
поделиться

2 ответа

Your code doesn't work because the function is not returning anything to print.

As far as algorithms go, how about this:

function getAge($then) {
    $then_ts = strtotime($then);
    $then_year = date('Y', $then_ts);
    $age = date('Y') - $then_year;
    if(strtotime('+' . $age . ' years', $then_ts) > time()) $age--;
    return $age;
}
print getAge('1990-04-04'); // 19
print getAge('1990-08-04'); // 18, birthday hasn't happened yet

This is the same algorithm (just in PHP) as the accepted answer in this question.

A shorter way of doing it:

function getAge($then) {
    $then = date('Ymd', strtotime($then));
    $diff = date('Ymd') - $then;
    return substr($diff, 0, -4);
}
34
ответ дан 1 December 2019 в 06:18
поделиться

You need to return $yearDiff, I think.

2
ответ дан 1 December 2019 в 06:18
поделиться
Другие вопросы по тегам:

Похожие вопросы: