Reputation: 87
I have searched around for an answer to my question and it seems the DATE_FORMAT function should allow me to remove the seconds - I need to format a column from my table and the results go into a drop-down box - I have the following code;
$DepartSailing = mysql_query("SELECT DATE_FORMAT(SailingTime,'%h:%i %p') AS FormattedTime FROM wp_timetable WHERE CURDATE() BETWEEN StartDate AND EndDate") or die(mysql_error());
echo "<select name='adults' id='adults' style='width: 300px; height: 30px; padding: 5px;'>";
while ($row= mysql_fetch_array($DepartSailing)) {
echo "<option value='" . $row['SailingTime'] ."'>" . $row['SailingTime'] ."</option>";}
echo "</select>";
The statement works if I just take out the DATE_FORMAT function. But it displays the seconds - can anybody tell me what I am doing wrong here?
Thanks
Upvotes: 2
Views: 163
Reputation: 74217
Since you're using an alias AS FormattedTime
You will need to change $row['SailingTime']
to $row['FormattedTime']
Here is a tutorial on aliases:
Here is an example that was pulled from that page:
SELECT [col1 | expression] AS `descriptive name`
FROM table_name
You're also using a deprecated MySQL API which will be removed from future PHP releases.
mysqli
with prepared statements, or PDO with prepared statements, they're much safer.Upvotes: 2