Reputation: 129
Ok, we have 2018-04-09T10:00:00
How to set time in:
DateTime::createFromFormat('Y-m-d\TH:i:s', $periodauction)->modify('-1 day, +4 hour')->format('Y-m-d\TH:i:s')
It will return 2018-04-08T14:00:00
, so it works fine.
But how to set specific time like 18
unstead +4 hour
. To get 2018-04-08T18:00:00
?
Upvotes: 3
Views: 4136
Reputation: 21
Set time.
$periodauction = '2018-04-09T10:00:00';
$date = DateTime::createFromFormat('Y-m-d\TH:i:s', $periodauction)->modify('-1 day t 18:00:00');
echo $date->format('Y-m-d\TH:i:s');
Or
$dateTime->modify('t 23:20:45');
Upvotes: 1
Reputation: 19780
You can use the method setTime()
to specify an hour and minutes:
$periodauction = '2018-04-09T10:00:00';
$date = DateTime::createFromFormat('Y-m-d\TH:i:s', $periodauction)->modify('-1 day');
$date->setTime(18,0);
echo $date->format('Y-m-d\TH:i:s');
Outputs:
2018-04-08T18:00:00
Upvotes: 6