View Single Post
Old 12-10-2007, 10:04 AM   #2 (permalink)
Geert
The Contributor
RegEx Guru 
 
Join Date: Dec 2007
Location: Belgium
Posts: 60
Thanks: 6
Geert is on a distinguished road
Default

Copied from Kohana's date helper:
PHP Code:
    /**
     * Adjusts a non-24-hour number into a 24-hour number.
     *
     * @param   integer  hour to adjust
     * @param   string   AM or PM
     * @return  string
     */
    
public static function adjust($hour$ampm)
    {
        
$hour = (int) $hour;
        
$ampm strtolower($ampm);

        switch(
$ampm)
        {
            case 
'am':
                if (
$hour == 12)
                    
$hour 0;
            break;
            case 
'pm':
                if (
$hour 12)
                    
$hour += 12;
            break;
        }

        return 
sprintf('%02s'$hour);
    } 
As you can see, you can use sprintf to autofill a number with zeroes.
__________________
Kohana - PHP5 framework
Geert is offline  
Reply With Quote