Page 1 of 1

Need help with display date

Posted: Fri Jul 22, 2011 11:54 am
by crowegreg
Hello, I'm needing assistance in displaying a date that is being retrieved from a mysql DB. Here's what I have so far:

while($row2 = mysql_fetch_array($result2)) {
echo "<tr>";
echo "<td>" . $row2['date'] . "</td><td>" . $row2['Notes'] . "</td>";
echo "</tr>";
echo "<br />";
}

All of this works, but my date is displayed as 2011-07-21. I'd like for it to be displayed as either 07-21-2011 or 07/21/2011.
Thanks for your assistance!!

Re: Need help with display date

Posted: Fri Jul 22, 2011 12:40 pm
by social_experiment
In your sql query you can use DATE_FORMAT().

Code: Select all

<?php
 $query = "SELECT DATE_FORMAT(dateField, '%m-%d-%Y')";
?>
Should display month-day-year (%d-%m-%Y will return day-month-year)

Re: Need help with display date

Posted: Fri Jul 22, 2011 2:34 pm
by crowegreg
Thanks for suggestion. If this is my original sql statement:
$sql2 = "SELECT wp_ebyz_card_usage.date, wp_ebyz_card_usage.Notes
FROM wp_ebyz_card_usage
WHERE wp_ebyz_card_usage.cardID='{$_POST[CardNumber]}' AND wp_ebyz_card_usage.merchantID='{$_SESSION['merchantid']}' ORDER BY wp_ebyz_card_usage.date DESC";

How do I add your suggestion to this statement?

Re: Need help with display date

Posted: Sat Jul 23, 2011 1:16 am
by social_experiment

Code: Select all

<?php
...DATE_FORMAT(wp_ebyz_card_usage.date, '%m-%d-%Y')...
?>
You have to modify the field that contains the date you want to use like the example above, it is simply added into the query