Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PHP / MySQL time format

0 views
Skip to first unread message

Neal

unread,
Feb 15, 2005, 7:14:28 PM2/15/05
to
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

unread,
Feb 15, 2005, 7:17:43 PM2/15/05
to
Neal wrote:

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($newArray["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:
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html#IDX1385

And there's also this article I wrote:
http://www.electrictoolbox.com/article/mysql/format-date-time-mysql/

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

0 new messages