Eric Evans
Eric Evans

Reputation: 670

DateInterval string Problems

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.

Upvotes: 2

Views: 318

Answers (1)

Pratik Soni
Pratik Soni

Reputation: 2588

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

P0Y0DT10H0M

Upvotes: 1

Related Questions