PDA

View Full Version : timestamp to useable date


urg
11-20-2002, 01:32 AM
How do I take the date information from a mysql timestamp (e.g., 20021117002521) and turn it into a date, on a php page, that people might be able to read (e.g., November 17, 2002)? I know how to grab it from the database. It's the converstion to a user-friendly format in php I need help with.

That's what I'm really after right now. But it would be nice to have the time in there too. How do I do the same thing with the time (e.g., so the above stamp would be converted to read "12:25 AM" - assuming I'm reading it correctly)?

-Brett

SnakEyez
11-20-2002, 01:47 AM
Well you could do it just as easily by having the date and time be 2 separate strings and have them inserted into 2 different columns in the database and then pull out the results. Here is the PHP.NET manual showing you how to manipulate the input of a date/time function to put into a database to make it easy to extract:

http://www.php.net/manual/en/function.date.php

urg
11-20-2002, 03:47 AM
Thanks. I was actually looking at the php.net site when I stopped briefly to read your note. It took a while to sift through the information there, but I got it working just the way I wanted. I wanted a specific display (shown here)

Sunday
November 17, 2002
at 12:25 AM

To get to that from the timestamp, I had to write the select string like this:

SELECT var1, ...,
DATE_FORMAT(timestampvar, '%W<BR> %M %d, %Y<BR>at %l:%i %p') AS newdate
FROM tablename

Then use the new variable called "newdate" to display the date.

-Brett