Page 1 of 1
[SOLVED]MySQL NOW() to php date
Posted: Tue Aug 21, 2007 8:37 pm
by mevets
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!
Posted: Tue Aug 21, 2007 9:08 pm
by Zoxive
Posted: Wed Aug 22, 2007 9:53 am
by pickle
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.
Posted: Wed Aug 22, 2007 10:07 am
by CoderGoblin
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);
Posted: Wed Aug 22, 2007 10:22 am
by RobertGonzalez
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.