I’m new to PHP and I am hoping that some here can help me further with date formatting in PHP. I have a range of dates that sometimes are as follows: 1914-00-00, or 1952-12-00 or 1990-01-31. Because some of the dates are historical, I don’t always have a month or a day.
I want the dates to display as follows (from example above):
1914
Dec 1952
01 Jan 1990
I’m trying to work with the following example, however it’s not working at all (opened is in DATE format)…
$result = mysqli_query($link, ‘SELECT store, opened FROM storez’);
while ($row = mysqli_fetch_array($result))
{
$supply = array(‘store’ => $row[‘store’], ‘opened’ => row[‘opened’]);
}
<div>
<?php echo date(‘M’,strtotime($item[‘opened’])); ?>
<?php echo date(‘d’,strtotime($item[‘opened’])); ?>,
<?php echo date(‘Y’,strtotime($item[‘opened’])); ?>
</div>
The dates that come back are as follows, which are not even close…
Nov 30, 1938
Dec 31, 1969
Nov 30, 1977
Hopefully, someone can help me with this problem. Maybe someone has run into this before? I’m sure it’s an easy fix, I just can’t think of another way. I’m trying to stay away from modifying the query, however if that is the only way, I’ll go down that road. Thank you again for reading my post and any help/suggestions would be greatly appreciated. --Ben