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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.