Calculations

use Derafu\Date\Support\DateCalculator;

What depends on the current date takes a clock as its last argument, and uses the clock of the system if it is not given one. The dates are DateTimeInterface objects or texts.

Method What it gives
DateCalculator::age($birth, $clock = null) The age in years.
DateCalculator::daysBetween($from, $to = null, $clock = null) The complete days from a date to another one (negative if the second is before). Without $to, until the clock.
DateCalculator::monthsBetween($from, $to = null, $clock = null) The months between the months of two dates, without looking at the days. A period written as 202511 is accepted instead of a date.
DateCalculator::countMatchingDays($from, $to, $days, $excludeWeekend = false) How many days of a range are in a list of Y-m-d dates.
DateCalculator::firstDayOfWeek($date = null, $clock = null) Monday of the week, at the start of the day.
DateCalculator::lastDayOfWeek($date = null, $clock = null) Sunday of the week, at the end of the day.
DateCalculator::years($total, $from = null, $clock = null) A list of years, from the most recent to the oldest.
DateCalculator::monthsBetween(202301, '2024-01-15');   // 12
DateCalculator::monthsBetween('2024-01-15', '2024-02-14');   // 1
DateCalculator::years(3, 2024);   // [2024, 2023, 2022]
On this page

Last updated on 05/11/2026 by Anonymous