7

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?

pixie123
  • 929
  • 3
  • 14
  • 27

3 Answers3

27
$my_date_time = date("Y-m-d H:i:s", strtotime("+1 hours"))
Louay Hamada
  • 781
  • 1
  • 14
  • 22
7

You can do this simply with strtotime function:

$my_date_time = date('Y-m-d H:i:s', strtotime('now +1 hour'));
Mohammad Hamedani
  • 3,304
  • 3
  • 10
  • 22
5

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');
Sahil Gulati
  • 15,028
  • 4
  • 24
  • 42