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
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
$time=time();
$datetime_from = date("Y-m-d H:i", strtotime("-43 minutes", strtotime("-6 hours",$time)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.