Search code examples
phphtmldateformatsubtraction

Need to remove Minutes from Date


$date = new DateTime("now", new DateTimeZone('Europe/Berlin') );
$dateUpdate = $date->format("d.m.Y H:i:s");

Hey, i need to subtract 4 Minutes from $dateUpdate. How is this possible?

Thanks


Solution

  • You can do it this way :

    $date = new DateTime("now", new DateTimeZone('Europe/Berlin'));
    $interval = new DateInterval("PT4M");
    $date->sub($interval);
    echo $date->format('Y-m-d\TH:i:s.u');
    

    DateTime Documentation

    DateInterval Documentation