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. Link to comment https://forums.phpfreaks.com/topic/96806-converting-ydm-format-to-longdate-eg-18-march-2008/ 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 Link to comment https://forums.phpfreaks.com/topic/96806-converting-ydm-format-to-longdate-eg-18-march-2008/#findComment-495391 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 ?> Link to comment https://forums.phpfreaks.com/topic/96806-converting-ydm-format-to-longdate-eg-18-march-2008/#findComment-495410 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 ?> Link to comment https://forums.phpfreaks.com/topic/96806-converting-ydm-format-to-longdate-eg-18-march-2008/#findComment-495427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.