2

I'm trying to do a math problem using datetime in php. The problem that the string that I'm creating is dynamic. If I add as a static string it runs fine, but If I make the string dynamic it fails. Here's a code example.

 $now = new DateTime();
$datetime_interval = 'P' . $filledOrder->hours . 'H'; // hours comes from an object
$now->add(new DateInterval($datetime_interval));

If I add static string to DateInterval is working fineenter code here

$now->add(new DateInterval('P10H'));

Any help would be greatly appreciated.

Eric Evans
  • 640
  • 2
  • 13
  • 31

1 Answers1

1

You Should consider entering full string as format like this way.

P0Y0DT10H0M

Pratik Soni
  • 2,498
  • 16
  • 26