0

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 ?

0

2 Answers 2

2

More a comment: Don't confuse the format of DateInterval with format of DateTime: i is 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanku. Yes i was using like that you said. Why they didnot used same format? One is opposite of another !
1

Per DateInterval, %i is "Minutes, numeric: 1, 3, 59". Try %I which uses leading zeroes.

1 Comment

Thanku. It is working. I used php.net/manual/en/function.date.php as reference ! that is my mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.