PHP / MySQL time format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neal

    PHP / MySQL time format

    I have a MySQL table with a datetime field that stamps the time the user
    submitted the form. It works and looks like this:

    $sql = "INSERT INTO table
    VALUES(....now( ))";

    On another php page to view results, the code:

    printf("<br><td > %s</td>\n",
    $newArray["datetime"]);

    makes it looks like: 2005-02-15 14:44:51

    I want it to look like:
    Wednesday 15th of January 2005 05:51:38 AM

    but when I try "date("l dS of F Y h:i:s A");" I get the format, but with
    the CURRENT time. I can't get the time stamped in that format. Thanks.
  • Chris Hope

    #2
    Re: PHP / MySQL time format

    Neal wrote:
    [color=blue]
    > I have a MySQL table with a datetime field that stamps the time the
    > user submitted the form. It works and looks like this:
    >
    > $sql = "INSERT INTO table
    > VALUES(....now( ))";
    >
    > On another php page to view results, the code:
    >
    > printf("<br><td > %s</td>\n",
    > $newArray["datetime"]);
    >
    > makes it looks like: 2005-02-15 14:44:51
    >
    > I want it to look like:
    > Wednesday 15th of January 2005 05:51:38 AM
    >
    > but when I try "date("l dS of F Y h:i:s A");" I get the format, but
    > with the CURRENT time. I can't get the time stamped in that format.[/color]

    Of course you get the current time. You need to pass a timestamp to the
    date() function to get a spefic date and time like so:

    date("l dS of F Y h:i:s A", strtotime($newA rray["datetime"]));

    The strtotime() function converts the mysql datetime into a timestamp
    suitable for passing to date().

    or else format the date and time directly in your query with the MySQL
    function DATE_FORMAT. More info about this here:


    And there's also this article I wrote:


    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    Working...