PHP Add Hours to Datetime Example

By Hardik Savani May 14, 2024 Category : PHP

In this example, you will learn how to add hours to date time in php. I’m going to show you about how to add hours to current date in php. it's simple example of how to add 12 hours to date in php. let’s discuss about how to add 5 hours to date in php.

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

Example 1: PHP Add 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 13:10:05

Example 2: PHP Add Hours to Current DateTime

index.php

<?php

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

echo $newDate;

?>

Output:

2021-11-10 06:49:33

i hope it can help you...

Tags :
Shares