How to add 5 minutes to current datetime on php < 5.3
You can use the strtotime
function in PHP to add a certain number of minutes to a date and time. For example, to add 5 minutes to the current date and time:
<?php
$current_time = time();
$new_time = $current_time + 5 * 60;
$new_datetime = date('Y-m-d H:i:s', $new_time);
echo "Current Time: " . date('Y-m-d H:i:s', $current_time) . "\n";
echo "New Time (5 minutes in the future): " . $new_datetime . "\n";
?>
Watch a video course
Learn object oriented PHP
Here, time()
gets the current timestamp, then we add 5 minutes (5 * 60 seconds) to the timestamp. Then, date
function is used to format the timestamp in the desired format.