DateTimeImmutable::sub Subtracts an amount of days, months, years, hours, minutes and seconds &reftitle.description; public DateTimeImmutableDateTimeImmutable::sub DateIntervalinterval Returns a new DateTimeImmutable object, with the specified DateInterval object subtracted from the specified DateTimeImmutable object. &reftitle.parameters; interval A DateInterval object &reftitle.returnvalues; &date.datetimeimmutable.return.modifiedobject; &reftitle.errors; If an unsupported operation is attempted, such as using a DateInterval object representing relative time specifications such as next weekday, a DateInvalidOperationException is thrown. &reftitle.changelog; &Version; &Description; 8.3.0 Now throws a DateInvalidOperationException instead of a warning when an unsupported operation is attempted. &reftitle.examples; <function>DateTimeImmutable::sub</function> example &style.oop; sub(new DateInterval('P10D')); echo $newDate->format('Y-m-d') . "\n"; ?> ]]> &examples.outputs; Further <function>DateTimeImmutable::sub</function> examples sub(new DateInterval('PT10H30S')); echo $newDate->format('Y-m-d H:i:s') . "\n"; $date = new DateTimeImmutable('2000-01-20'); $newDate = $date->sub(new DateInterval('P7Y5M4DT4H3M2S')); echo $newDate->format('Y-m-d H:i:s') . "\n"; ?> ]]> &example.outputs; Beware when subtracting months sub($interval); echo $newDate1->format('Y-m-d') . "\n"; $newDate2 = $newDate1->sub($interval); echo $newDate2->format('Y-m-d') . "\n"; ?> ]]> &example.outputs; &reftitle.seealso; DateTimeImmutable::add DateTimeImmutable::diff DateTimeImmutable::modify