ThisisForReal Posted June 4, 2010 Share Posted June 4, 2010 I'm currently storing some date and time information in a MySQL column that has a date time format: "2010-06-04 17:35:00". I am in an html table using php's foreach { to cycle through my query results and create <td> tags to separate the date and time into separate columns within the table. e.g. echo '<td>' . $date . '</td><td>' . $time '</td>'; I would love to display the data to the user in a more useful format ("June 4", "5:35 pm"). I know that to do that I'd be using PHP's 'M' and 'j', for one column and 'g' 'i' and 'a' for the other. I am having a total brainfart on transforming the data for display (that, and I'm new to php). You don't need to point it out, but as you can imagine I'm getting the server time returned to me, instead of what's in my DB table: foreach($meals as $display) { $date = $meals['mealDateTime']; $date = date('M j'); $time = $meals['mealDateTime']; $time = date('g:i a'); echo '<tr><td>'; echo $date; echo '</td><td colspan="4">'; echo $time; echo '</td></tr>'; } I'm just asking what the proper syntax is to get the datetime value returned in my query and use the php date functions to display it correctly. Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/203860-syntax-guidance-to-use-mysql-datetime-for-html-table-with-php/ Share on other sites More sharing options...
DavidAM Posted June 4, 2010 Share Posted June 4, 2010 First convert the data to a unix timestamp using strtotime(), then use the date() function to format it: $datetime = strtotime($meals['mealDateTime']); $date = date('M j', $datetime); $time = date('g:i a', $datetime); Quote Link to comment https://forums.phpfreaks.com/topic/203860-syntax-guidance-to-use-mysql-datetime-for-html-table-with-php/#findComment-1067704 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.