PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am storing the time and date that users upload images. I do this by using NOW() in my mysql query and DATETIME as my datatype. I get dates like this:
When the user goes and looks at the time that they uploaded the image I dont want to make them look at that. Instead, I want it to look more like this:
Does anyone know how this should be done? I suspect I am adding the dates to the database incorrectly and should instead be using the number of seconds since the unix epoch, but I dont know how that is done. Articles on this particular circumstance are welcome as well!
Thanks!
Last edited by mevets on Wed Aug 22, 2007 2:28 pm, edited 1 time in total.
I would suggest using the DATE_FORMAT MySQL function that ~Zoxive mentioned. However, if you want to get a unix timestamp out of that column, the easiest way would be to use the UNIX_TIMESTAMP MySQL function.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Be very careful when using strtotime if you ever use it.
PHP Manual wrote:The function expects to be given a string containing a US English date format
so 12/01/2007 is 1st December not 12th January as it should be in europe (rest of the world ?). I've run afoul of it in the past.
While I'm here the postgres version to get the php time is "select date_part('epoch',now())" in case anyone is looking at this thread and wondering how to do it (despite the MYSQL in the topic title);
Either modify the date format at the database server or return a Unix time stamp from the database server and manipulate it in PHP. I would go with the first choice rather than the second in this case.