How to subtract seconds from time in PHP
In this tutorial, we will learn How to subtract seconds from time in PHP. I will explain an easy way to create PHP subtract seconds from the current time. You understand how to subtract seconds from time in PHP. So, let’s discuss how to subtract seconds from the current time in PHP. Subtracting time (hours, minutes, and seconds) from date can be easily using the date() and strtotime() function in PHP. You can use two functions together to subtract time from the current date using PHP.
Here, I will provide two examples.
Also read: How to subtract hours from the time in PHP
- PHP Subtract Seconds to time.
- PHP Subtract Seconds to Current time.
I will give you a simple example of how to subtract seconds from time in PHP. Here, create a simple example of subtracting 30 seconds from the current time in PHP.
PHP Subtract Seconds to time
Also read: How to subtract minutes from time in PHP
Example
<?php
$custom_time = "09:16:40";
$new_time = date('H:i:s', strtotime($custom_time. ' -30 seconds'));
echo $new_time;
?>
Output
09:16:10
PHP Subtract Seconds to Current time
Example
<?php
// current time: 09:26:40
$new_time = date('H:i:s', strtotime(' -30 seconds'));
echo $new_time;
?>
Output
09:26:10