Jump to content

Formatting a Date pulled from MySQL


blikecray

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/197224-formatting-a-date-pulled-from-mysql/
Share on other sites

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')"; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.