-4

I have this code:

<?php 
    $date = date('Y-m-d H:i:s', strtotime('-6 hours', (int)get_the_time('U'))); 
    echo $date; 
?>

as you can see the time is changed by subtracting 6 hours from the time, what I want to subtract the hours and also minutes so I tried this:

<?php 
    $date = date('Y-m-d H:i:s', strtotime('-6 hours', '-23 minutes', (int)get_the_time('U'))); 
    echo $date; 
?>

But isn't working, any idea?

Thank you in advance

Michele Petraroli
  • 89
  • 1
  • 1
  • 11
  • 2
    Possible duplicate of [PHP, use strtotime to subtract minutes from a date-time variable?](https://stackoverflow.com/questions/11688829/php-use-strtotime-to-subtract-minutes-from-a-date-time-variable) – Abdulla Nilam Oct 19 '17 at 07:39
  • `strtotime` only accepts 2 arguments, not 3. Put the hours and minutes into the same string. – deceze Oct 19 '17 at 07:43

2 Answers2

7

The strtotime function expecting only 2 parameters.

int strtotime ( string $time [, int $now = time() ] )

So you should try the following format:

$date = strtotime('-6 hours, -43 minutes', $time);

Tested Code:

<?php
$time = time();
$date = strtotime('-6 hours', $time);
echo date('d-m-y H:i', $time);
echo date('d-m-y H:i', $date);


$date = strtotime('-6 hours, -43 minutes', $time);
echo date('d-m-y H:i', $time);
echo date('d-m-y H:i', $date);

Output:

19-10-17 00:44
18-10-17 18:44

19-10-17 00:44
18-10-17 18:01
Ofir Baruch
  • 10,323
  • 2
  • 26
  • 39
0
$time=time();
$datetime_from = date("Y-m-d H:i", strtotime("-43 minutes", strtotime("-6 hours",$time)));
Osama
  • 2,912
  • 1
  • 12
  • 15