nisroc Posted December 28, 2013 Share Posted December 28, 2013 I have a mysql date 0000-00-00 in a database of 3000+ entries but on my page i would perfer it to write out as Y-M-d or even d-M-Y. I have flipped though some examples but they all seem to adjust the date before it goes into the database. All i want is it to more clear which will allow easier sorting. is it possible to change the date as it is pull from a database? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 29, 2013 Share Posted December 29, 2013 (edited) You can change the date in your MySQL queries using the DATE_FORMAT function, eg SELECT DATE_FORMAT(your_date_col, 'Y-M-d') as formatted_date FROM table Edited December 29, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
nisroc Posted December 30, 2013 Author Share Posted December 30, 2013 (edited) You can change the date in your MySQL queries using the DATE_FORMAT function, eg SELECT DATE_FORMAT(your_date_col, 'Y-M-d') as formatted_date FROM table I found an example on the internet which seemed to work Ch0cu3r. <?php echo date('F d, Y', strtotime($row_draws['Date'])); ?> I am unsure if this is correct but it does not throw an error, is there anything wrong with using this? Edited December 30, 2013 by nisroc Quote Link to comment Share on other sites More sharing options...
Ritual29 Posted January 1, 2014 Share Posted January 1, 2014 I'm not familiar with the php method, but it's way better to let mysql do the formatting. mysql can do this alot quicker than php. mysql has a special built in function for it. So I recommend to use that. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 5, 2014 Share Posted January 5, 2014 @Ritual29, the nonspecific answer you have provided has already been given, with much greater detail, with the name of the function, a link to its documentation, and an example, in a previous reply in this thread. please don't parrot answers already in the thread unless you are adding helpful information to the thread. 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.