2

If DateTime $serverTime is e.g. 2016-02-03 00:30:00 and i subtract 90 minutes like this

$serverTime->sub(new DateInterval("PT1H30M"));

the $serverTime is now 2016-02-03 23:00:00. Notice that the date remains February 3rd. While it's exepcted that it goes down by one - it should be 2016-02-02 23:00:00. Is there another way to achieve this?

IanDess
  • 657
  • 2
  • 11
  • 26

1 Answers1

3

You are doing something wrong or modifying it along the way:

$serverTime = DateTime::createFromFormat('Y-m-d H:i:s', '2016-02-03 00:30:00');
print_r($serverTime);
$serverTime->sub(new DateInterval("PT1H30M"));
print_r($serverTime);

Works fine for me: Demo.

Aziz Saleh
  • 2,687
  • 1
  • 17
  • 27