ORLANDev.com

Manipulation of Date

Let's take an example that in my MySQL database I have the time I posted this articles saved in the current format: "YYYY-mm-dd H:i:s". If I show the time saved in the database as it is it will be: 2009-01-30 15:00:00.

If you would like to change the date around and show it as you wish, check out this function which you might find it handy. <?
    
//Parameters
    // - $date = A string date such as "2009-01-30 15:00:00"
    // - $format = The new format you want the date such as "30/01/2009 15:00"
    
function dateFormat($date$format)
    {
        
$datetoformat = new Datetime($date);
        return 
date_format($datetoformat$format);
    }
    
    
//Check out www.php.net/date for the symbols of how you can represent a date
    
echo dateFormat("2009-01-30 15:00:00""d/m/Y H:i");
?>
posted on 30/01/2009 | (PHP)

Archives

+
 2009