DateInterval¶
DateInterval is a class for the representation of period of time, or stretch of time. It may be added to DateTimeImmutable and DateTime objects. It is only created as a time duration.
<?php
// Create a specific date
$someDate = \DateTime::createFromFormat('Y-m-d H:i', '2022-08-25 14:18');
// Create interval
$interval = new \DateInterval('P7D');
// Add interval
$someDate->add($interval);
// Convert interval to string
echo $interval->format('%d');
?>
See also PHP: Dominate dates with intervals and periods.
Related : DateTime, DateTime, Datetime Trap, Calendar, Clock, DateTimeInterface
Related packages : league/period