clairian Posted March 18, 2008 Share Posted March 18, 2008 Hi, I am storing dates in my database in the usual date format (yyyy,dd,mm) Is there any way to use php to display this db data in a more readable 'longdate' format - e.g. 18 March 2008? Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 18, 2008 Share Posted March 18, 2008 Do something in your query like this DATE_FORMAT(time, '%W %D %M %Y') as date where time is the field in your database Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 18, 2008 Share Posted March 18, 2008 or <?php $date = '2008,18,03'; // we need to rearrange the parts for strtotime() to recognize it $parts = explode(',', $date); $formatted_date = date('j F Y', strtotime($parts[0].$parts[2].$parts[1])); echo $formatted_date; // 18 March 2008 ?> Quote Link to comment Share on other sites More sharing options...
clairian Posted March 19, 2008 Author Share Posted March 19, 2008 The code below has done the job. Thanks - it will be a great help. <?php $date = '2008,18,03'; // we need to rearrange the parts for strtotime() to recognize it $parts = explode(',', $date); $formatted_date = date('j F Y', strtotime($parts[0].$parts[2].$parts[1])); echo $formatted_date; // 18 March 2008 ?> 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.