I use this code:
$today_date = new DateTime('now');
$final_date = new DateTime('2012-03-22 09:00');
$interval = $today_date->diff($final_date);
$time_left = $interval->format('%d:%H:%i:%s');
I want $time_left to have the format dd:hh:mm:ss format (d-> day, h-> hour, m-> minute, s-> seconds).
But when i used %d:%H:%i:%s as format, it sometimes displays single number, that is without 0 padding for minute. For example: 11:14:7:45. Expected result: 11:14:07:45
Any mistakes ?
More a comment: Don’t confuse the
formatofDateIntervalwithformatofDateTime:iis Minutes, numeric, e.g. 1, 3, 59. In case you run into a problem or you use a function you don’t know in and out, please consult the manual first.