Sarah92
Sarah92

Reputation: 87

MySQL Date without seconds

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

Answers (1)

Funk Forty Niner
Funk Forty Niner

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.

Upvotes: 2

Related Questions