PHP Time Stamp

Associate
Joined
16 Aug 2004
Posts
268
I'm having some trouble understanding how to convert a timestamp (2008-02-20 15:45:00) into something like "20th Feb 2008, 3:45pm"

All the examples I have found use the current time/date at the moment you use the function just not sure how to use a specific time/date already stored in a variable.

Hope that makes sense as I'm new to php and not sure If I have used the correct terminology.
 
that's a MySQL datetime, not a timestamp :)

run that through strtotime() and then have a look at date() to convert it to your desired format
 
that's a MySQL datetime, not a timestamp :)

run that through strtotime() and then have a look at date() to convert it to your desired format

Actually, it is a timestamp - MySQL present their datetime fields in the aforementioned timestamp format.
 
Actually, it is a timestamp - MySQL present their datetime fields in the aforementioned timestamp format.

I suppose semantically it is. I'm pretty sure I remember it has its own standard but I couldn't be arsed to look for it. I meant that it wasn't a Unix timestamp that PHP needs it to be in its date functions. Sorry for any confusion.

if this is a value from a mysql database, you could format it using "date_format" in your query as opposed to using php.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format

i don't suppose it makes much difference though. :p

if you were feeling really adventurous, you could use the UNIX_TIMESTAMP() function to convert it and play with it in PHP. Like you say, though, it probably doesn't make too much difference (depending on what you need to do with the date once you've retrieved it)
 
Back
Top Bottom