dennismonsewicz Posted February 3, 2009 Share Posted February 3, 2009 I have a field in my DB that contains the current timestamp when an entry is posted into the DB... the timestamp shows like this currently, 2009-02-02 21:03:52... but how do i get it to show like this: 02/02/2009? Quote Link to comment Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 MySQL DATE_FORMAT Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted February 3, 2009 Share Posted February 3, 2009 Or use php's date function: $stamp = "2009-02-02 21:03:52"; print date("d/m/Y", strtotime($stamp)); Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 3, 2009 Author Share Posted February 3, 2009 sweet it worked! Thanks Neil! Also thanks premiso... i didn't know about the thing in mysql! Quote Link to comment Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 Or use php's date function: $stamp = "2009-02-02 21:03:52"; print date("d/m/Y", strtotime($stamp)); Which would be about 8-10x slower than using MySQL's EDIT: Decided to add an example: SELECT DATE_FORMAT(`datefield`, '%d/%c/%Y') FROM table_name WHERE condition = something; Quote Link to comment Share on other sites More sharing options...
JonnoTheDev Posted February 3, 2009 Share Posted February 3, 2009 Yeah but its hardly gonna bring a server crashing down. Take your pick on which method you use. Quote Link to comment Share on other sites More sharing options...
premiso Posted February 3, 2009 Share Posted February 3, 2009 Yeah but its hardly gonna bring a server crashing down. Take your pick on which method you use. No, it will not. But why not pull the data out how you want it formatted when the tool is right there? That and using MySQL DATE_FORMAT will not have the limits of strtotime, which are limits of the OS. I do not believe on a UNIX system strtotime can go past 2039. Anyhow, not to put you down. Just decided to add my reasoning. Either way works. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted February 3, 2009 Author Share Posted February 3, 2009 well i couldn't get the mysql way to work so I used the PHP way and it worked fine... but i reckon both work just as great! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.