How to Subtract Minutes to Date and Time in PHP

The following is a really easy way to subtract minutes in date and time using PHP. Using the date function to set the format of the date to be returned then using strtotime.

The following source code will subtract 2 minutes to current date and time.

<?php
    $start = date('Y-m-d H:i:s');
    echo date('Y-m-d H:i:s',strtotime('-2 minutes',strtotime($start)));
?>

The following source code will subtract 2 minutes to date and time.

<?php
    $start = '2018-05-21 20:24:45';
    echo date('Y-m-d H:i:s',strtotime('-2 minutes',strtotime($start)));
?>

And if you like this tutorials please share it with your friends via Email or Social Media.

Leave a Reply

Your email address will not be published. Required fields are marked *