dadedidhodong Posted August 19, 2013 Share Posted August 19, 2013 I have a php program which accepts the input of the YYYY-MM-DD as the date format and stores it to the database. As soon as the user enters the date with YYYY-MM-DD format (e.g 1990-06-22) how can I convert the 06 (or the MM part) to June as in the 6th month of the year? Link to comment https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/ Share on other sites More sharing options...
cyberRobot Posted August 19, 2013 Share Posted August 19, 2013 Is there a reason why you don't want to store the date as YYYY-MM-DD? That format is more useful for things like sorting. When displaying the data, you could always use MySQL's date_format() function: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/#findComment-1445799 Share on other sites More sharing options...
incipience Posted August 19, 2013 Share Posted August 19, 2013 <?php $date = new DateTime('2000-01-01'); echo $date->format('F j, Y'); ?> This would display as January 1, 2000 Link to comment https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/#findComment-1445804 Share on other sites More sharing options...
Evan_McIntosh Posted August 19, 2013 Share Posted August 19, 2013 <?php date_default_timezone_set('America/Vancouver'); $date = '2099-12-31'; echo date('F j, Y', strtotime($date)); ?> = December 31, 2099 http://php.net/manual/en/function.date.php http://php.net/manual/en/function.strtotime.php Link to comment https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/#findComment-1445824 Share on other sites More sharing options...
dadedidhodong Posted August 23, 2013 Author Share Posted August 23, 2013 thank you very much guyz :] Link to comment https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/#findComment-1446449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.