blikecray Posted April 1, 2010 Share Posted April 1, 2010 Hello all, I wanted to see if anyone could help me with this small issue. This is my current code, it pulls from a sql database that lists my users names and birthdays. It is programmed to show the upcoming birthdays for the next month. The only issue is that it shows the users entire birthday. (1984-12-23) I would much rather it show just the month and day (12-23). Can anyone show me what I need to change in this code to make that work? The data type is DATE within my database for the birthday column. <? $result1 = mysql_query("SELECT name, birthday FROM address WHERE MONTH(birthday) = MOD(MONTH(CURDATE()), 12)"); echo "<table><tr><th>Name</th> <th>Date</th> </tr>"; while ($row1 = mysql_fetch_array($result1)) { $sql = "SELECT *, DATE_FORMAT(birthday, '%d/%m/%Y')"; echo "<tr>"; echo "<td>" . $row1['name'] . "</td> <td> " . $row1['birthday'] . "<br></td>"; echo "</tr></table>"; } ?> Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/197224-formatting-a-date-pulled-from-mysql/ Share on other sites More sharing options...
harristweed Posted April 1, 2010 Share Posted April 1, 2010 change: $result1 = mysql_query("SELECT name, birthday FROM address WHERE MONTH(birthday) = MOD(MONTH(CURDATE()), 12)"); to: $result1 = mysql_query("SELECT name, DATE_FORMAT(birthday, '%d-%m') as birthday FROM address WHERE MONTH(birthday) = MOD(MONTH(CURDATE()), 12)"); delete: $sql = "SELECT *, DATE_FORMAT(birthday, '%d/%m/%Y')"; Quote Link to comment https://forums.phpfreaks.com/topic/197224-formatting-a-date-pulled-from-mysql/#findComment-1035237 Share on other sites More sharing options...
blikecray Posted April 1, 2010 Author Share Posted April 1, 2010 Perfect! Thank you so much man. Works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/197224-formatting-a-date-pulled-from-mysql/#findComment-1035251 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.