1
if (empty($krow['BUSSTRT'])){ 
    $busts = $ts->add(new DateInterval('PT6i5s'));
    $busDate = $busts->format('m/d/Y H:i:s');
    echo "busDate:".$busDate."<br>\n";
}else{
    $busts = new DateTime($krow['BUSSTRT']);
    $busDate = $busts->format('m/d/Y H:i:s');
    echo "busSTRT:".$busDate."<br>\n";
}   

if (empty($krow['LAMISTRT'])){ 
    echo "lamistrt is empty::::";
    $lamts = $busts->add(new DateInterval('PT11is'));
    $lamDate = $lamts->format('m/d/Y H:i:s');
    echo "lamDate:".$lamDate."<br>\n";
}else{
    $lamts = new DateTime($krow['LAMISTRT']);
    $lamDate = $lamts->format('m/d/Y H:i:s');
    echo "lamistrt:".$lamDate."<br>\n";
} 

The code above is throwing the following error:

PHP Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (PT11i3s)'

when $bustDate is:

busSTRT:02/06/2015 03:53:56 lamistrt is empty::::

What am I missing here?

John Conde
  • 217,595
  • 99
  • 455
  • 496
dft99
  • 69
  • 8

1 Answers1

1

When using DateInterval() to create an interval you use M for minutes, not i. Also, if there are no seconds you must omit it from the interval declaration:

$busts = $ts->add(new DateInterval('PT6M5S'));
$lamts = $busts->add(new DateInterval('PT11M'));

i is used for getting the number of minutes in a date interval:

echo $intervalObj->i; // get minutes
Glavić
  • 42,781
  • 13
  • 77
  • 107
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Thank you John. I was thrown off by this http://php.net/manual/en/class.dateinterval.php – dft99 Mar 10 '15 at 19:18
  • And since that DateInterval terminology is ... interesting, have a look at something like Carbon: http://carbon.nesbot.com/ - that uses real english for things and extends DateTime – thinice Mar 10 '15 at 19:33