denhamd2 Posted October 28, 2010 Share Posted October 28, 2010 Hi, I have a date string being output from a database into a variable $date which looks like: $date = "2010-09-30 12:45:52"; I'm trying to change the format to: 30 September 2010 (I want to get rid of the time also) Does anyone know how I could do this in PHP? Any help would be much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/217104-problem-changing-the-format-of-a-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 28, 2010 Share Posted October 28, 2010 You can do this directly in your query - http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format It is about 8-10x faster to do this in your query when you retrieve the data than if you use some php code to do this. Quote Link to comment https://forums.phpfreaks.com/topic/217104-problem-changing-the-format-of-a-date/#findComment-1127578 Share on other sites More sharing options...
denhamd2 Posted October 28, 2010 Author Share Posted October 28, 2010 Hi, Unofrtunately I have no access to the query. It needs to be done in PHP. Any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/217104-problem-changing-the-format-of-a-date/#findComment-1127597 Share on other sites More sharing options...
PFMaBiSmAd Posted October 28, 2010 Share Posted October 28, 2010 There are examples posted all over using strtotime() and date() Quote Link to comment https://forums.phpfreaks.com/topic/217104-problem-changing-the-format-of-a-date/#findComment-1127600 Share on other sites More sharing options...
litebearer Posted October 28, 2010 Share Posted October 28, 2010 Perhaps... <?PHP $date = "2010-09-30 12:45:52"; echo date("d F Y", strtotime($date)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/217104-problem-changing-the-format-of-a-date/#findComment-1127618 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.