How to Add Seconds to Time in PHP?

By Hardik Savani November 5, 2023 Category : PHP

In this tutorial we will go over the demonstration of how to add seconds to time in php. We will look at example of php add seconds to time. you will learn add 15 seconds to time in php. i would like to share with you how to add 10 seconds to current time in php.

I will give you very simple example how to add seconds to datetime in PHP. so let's see both example with output:

Example 1: PHP Add Seconds to Time

index.php

<?php

$date = "10:10:05";

$newDate = date('H:i:s', strtotime($date. ' +10 seconds'));

echo $newDate;

?>

Output:

10:10:15

Example 2: PHP Add Seconds to Current DateTime

index.php

<?php

$newDate = date('H:i:s', strtotime('+10 seconds'));

echo $newDate;

?>

Output:

04:05:51

i hope it can help you...

Tags :
Shares