PHP Add one hour to current date time

27,853

Solution 1

$my_date_time = date("Y-m-d H:i:s", strtotime("+1 hours"))

Solution 2

You can do this simply with strtotime function:

$my_date_time = date('Y-m-d H:i:s', strtotime('now +1 hour'));

Solution 3

Here we are using DateTime and DateInterval for getting desired output.

Try this code snippet here

<?php
ini_set('display_errors', 1);

$dateTimeObj= new DateTime();
$dateTimeObj->add(new DateInterval("PT1H"));
echo $dateTimeObj->format('Y-m-d H:i:s');
Share:
27,853
pixie123
Author by

pixie123

Updated on July 22, 2022

Comments

  • pixie123
    pixie123 almost 2 years

    here is my code for the current date time (now):

    $my_date_time = date('Y-m-d H:i:s');
    

    how can I add one hour while keeping that format?