diff --git a/index.php b/index.php index 4573d8d9868f489c6e410e4b02854700dbe1536e..b20577d669cf5a4e96d45f79e5c60258ac92da9c 100644 --- a/index.php +++ b/index.php @@ -94,5 +94,12 @@ print $e->getMessage(); } ?> + + +

Function 7

+ Разница дней: "; + print $func->diffDays(new DateTimeImmutable(), new DateTimeImmutable("2025-01-01")); + ?> \ No newline at end of file diff --git a/src/Functions.php b/src/Functions.php index f7b52aa43644e535ee393f3fc3973a396378c55e..aca1d299d3aca876d91a9ee0b41ea82750768726 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -169,5 +169,17 @@ class Functions yield new DateTimeImmutable($day->format("Y-m-d")); } } + + /** + * Вернет кол-во дней между датами + * @param DateTimeImmutable $dateStart дата начала + * @param DateTimeImmutable $dateEnd дата окончания + * @return int + */ + public function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int + { + $dateInterval = date_diff($dateStart, $dateEnd); + return (int)$dateInterval->format("%a") ; + } }