minutes without leading 0

Posted on 2014-08-15
Last Modified: 2014-08-15

In this line of code:

(($diff->format('%d')*24) + $diff->format('%h')) . ":" . $diff->format('%i');

If result is 25 hours with 20 minutes works well and displays 25:20, but when the minutes are less than 10, like 7 results in sometime like that 25:7, how i can change the format of the minute to have a leading 0, like 25:07?
Question by:joyacv2
    LVL 58

    Accepted Solution



    str_pad($diff->format('%i'), 2, '0', STR_PAD_LEFT);
    LVL 1

    Author Comment

    Hi Gary,

    Is there a way to make this result sortable in the table? Thanks!!!!
    LVL 58

    Expert Comment

    Sortable in what table - this is probably a new question.
    LVL 1

    Author Comment


    I will accept your solution that works perfect and open a new question! Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now