outchy Posted August 17, 2008 Share Posted August 17, 2008 Not sure if this question belongs here or in the MySQL section but I think it goes here... Let's say I have a MySQL database entry that is a date in YYYY-DD-MM format. Is there a way to take that date and display it in a more readable format (say 'January 1, 2008') on a php webpage? Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/ Share on other sites More sharing options...
dezkit Posted August 17, 2008 Share Posted August 17, 2008 $date = date("F n, Y"); and then just insert into database Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618352 Share on other sites More sharing options...
Fadion Posted August 17, 2008 Share Posted August 17, 2008 I guess the guy wants to display an existing date. You can use this: <?php $date = '2008-08-17'; //mysql uses YYYY-MM-DD if you're using the mysql date data type list($year, $month, $day) = explode('-', $date); //get individual variables for year, month and day echo date('F j, Y', mktime(0, 0, 0, $month, $day, $year)); //print the date using a custom format ?> Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618467 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 See date/time functions such us date_parse() (an alternative for explode() GuiltyGear used) or strtotime() Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618469 Share on other sites More sharing options...
Barand Posted August 17, 2008 Share Posted August 17, 2008 $date = date("F n, Y"); and then just insert into database NO! NO! NO! That would be a totally useless format to store in a DB. Always format on output, by using one of either - MySQL's DATE_FORMAT() function - PHP's date() function Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618480 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 I guess the guy wants to display an existing date. You can use this: <?php $date = '2008-08-17'; //mysql uses YYYY-MM-DD if you're using the mysql date data type list($year, $month, $day) = explode('-', $date); //get individual variables for year, month and day echo date('F j, Y', mktime(0, 0, 0, $month, $day, $year)); //print the date using a custom format ?> Okay, could you tell me how I would apply this code to my particular case (which is a simple concert database)? And yes, I am trying to pull out the "dateofshow' variable from the database and display it as 'January 1, 2008' or something like that. Here are the three relevant .php files in plain text: http://www.warehamps.org/nik/index.txt http://www.warehamps.org/nik/insert.txt http://www.warehamps.org/nik/add.txt Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618533 Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 Instead of: $rows['dateofshow'] use: date('F j, Y',strtotime($rows['dateofshow'])) Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618537 Share on other sites More sharing options...
outchy Posted August 17, 2008 Author Share Posted August 17, 2008 Instead of: $rows['dateofshow'] use: date('F j, Y',strtotime($rows['dateofshow'])) PERFECT! Thank you!! Quote Link to comment https://forums.phpfreaks.com/topic/120037-solved-convert-yyyy-dd-mm-to-display-in-a-more-readable-format/#findComment-618544 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.