I've some some php that changes the format of the time retrieved from the database:
$selectedDate = $_GET['date'];
$formatedDate = date("Y-d-m",strtotime($selectedDate)); // Y-m-d outputs Y-d-m oddly
echo "<form name='selectedDate' action='info.php' method='GET'>";
echo "<select name='date' onchange='this.form.submit()'>";
echo "<option value=select>Select a Date</option>";
while ($row = mysql_fetch_array($result))
{
$date = date("m-d-Y",strtotime($row['date']));
echo "<option>" . $date . "</option>";
}
echo "</select>";echo "<br />";
echo $selectedDate; // 1.) in: 02-13-2013, 2.) in: 02-12-2013
echo "<br />";
echo $formatedDate; // 1.) out: 1970-01-01, 2.) out: 2013-02-12
echo "<br />";
echo date("Y-m-d");
echo "<noscript>";
echo "<input type='submit' value='Select'>";
echo "</noscript>";
echo "</form>";
Now, for $formatedDate
, as stated, if I use Y-m-d
for output, I get 2013-12-02
instead of 2013-02-12
. Not to mention that even though all $selectedDate
's are in m-d-Y
before being formatted, it doesn't recognize them as dates
. I have the feeling that it's something totally silly that I'm missing, but I just can't see it.
So my question is, why does the strtotime()
reverse my month and days, and why does it not recognize all dates? Is there a better way of getting this done?