Formatting MySQL dates from the database with PHP

Discussion in 'PHP' started by Unihost, Sep 24, 2010.

  1. #1
    Storing the current date into a MySQL database table is easy. Here’s a tip on how to format a stored date using PHP at runtime with no complicated programming involved.

    I'll assume you have a database field, called date and set as type, date. You've probably added the recordset and also called the field into your page, but it displays as 2010-09-24 and you want to change the output.

    Here's the code

    <?php

    // Setting up the variable
    $date = date(‘m/d/Y’));

    // display the date
    echo “Date: ” . $date;

    // You can also change it to d/m/Y or whicever way you prefer.

    ?>
     
    Unihost, Sep 24, 2010 IP