ItSolutionStuff.com

How to Subtract Hours from DateTime in PHP?

By Hardik Savani β€’ May 14, 2024
PHP

Now, let's see example of php subtract hours from datetime. let’s discuss about php subtract hours from current time. this example will help you how to subtract hours from time in php. I’m going to show you about how to subtract hours from current time in php. Let's get started with subtract 1 hour from current time in php.

I will give you very simple example how to sub hours to date and time in PHP. so let's see both example with output:

Example 1: PHP Subtract Hours to DateTime

index.php

<?php

$date = "2021-11-01 10:10:05";

$newDate = date('Y-m-d H:i:s', strtotime($date. ' -3 hours'));

echo $newDate;

?>

Output:

2021-11-01 07:10:05

Example 2: PHP Subtract Hours to Current DateTime

index.php

<?php

$newDate = date('Y-m-d H:i:s', strtotime(' -3 hours'));

echo $newDate;

?>

Output:

2021-11-10 03:49:33

i hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

PHP Add Minutes to Time Example

Read Now β†’
β˜…

PHP Add Hours to Datetime Example

Read Now β†’
β˜…

PHP Subtract Year from Date Example

Read Now β†’
β˜…

PHP Subtract Month from Date Example

Read Now β†’
β˜…

How to Subtract Days to Date in PHP?

Read Now β†’
β˜…

How to Add Year to Date in PHP?

Read Now β†’
β˜…

How to Add Months to Date in PHP?

Read Now β†’
β˜…

How to Add Days to Date in PHP?

Read Now β†’