A
A
Alic_shadow2017-11-25 00:59:38
Oracle
Alic_shadow, 2017-11-25 00:59:38

How to get the difference of two dates?

5. Write a function that returns, as a character string, the number of years, months, days, hours, minutes, and seconds between the given dates. Leap years are taken into account.
For example, between the dates 02/01/2016 and 03/01/2016:
0 years, 1 month, 29 days, 696 hours, 41760 minutes, 2505600 seconds
When displaying information, display text in accordance with the rules of the Russian language. For example:
For the number "1" - year, month, day, hour, minute, second
For the number "3" - year, month, day, hour, minute, second
For the number "5" - years, months, days, hours, minutes, seconds
I can calculate the difference itself, but I don’t know how to insert the words “year, month, etc.” with the correct ending, tell me))))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2017-11-25
@AndryG

public static function endingsForm($n, $form1, $form2, $form5) {
    $n = abs($n) % 100;
    $n1 = $n % 10;
    if ($n > 10 && $n < 20) return $form5;
    if ($n1 > 1 && $n1 < 5) return $form2;
    if ($n1 == 1) return $form1;
    return $form5;
}

endingsForm(7, 'год', 'года', 'лет')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question