Reputation: 139
I have a date type column in MySQL (yyyy-mm-dd). I'd like to display the month abbreviation and day number only on a php webpage. I do not want to display the year. I did look through http://php.net/manual/en/function.date.php but coding isn't something I do everyday.
Upvotes: 1
Views: 1505
Reputation: 1374
Eg:
Database Table: Your_Table
Date Field : reg_date
Code
<?php
$qry = "SELECT reg_date FROM Your_Table";
$res = mysqli_query($conn,$qry);
if (mysqli_num_rows($res) > 0)
{
while($row = mysqli_fetch_assoc($res))
{
$date = $row['reg_date'];
$day_month = date('d M', strtotime($date));
echo $date.' = '.$day_month.'<br />';
}
}
?>
Upvotes: 0
Reputation: 6065
Use date_format
to do this:
mysql> select date_format('2016-01-02', '%b %e');
+------------------------------------+
| date_format('2016-01-02', '%b %e') |
+------------------------------------+
| Jan 2 |
+------------------------------------+
1 row in set (0.00 sec)
Upvotes: 1