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!!
Need help with display date
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Need help with display date
In your sql query you can use DATE_FORMAT().
Should display month-day-year (%d-%m-%Y will return day-month-year)
Code: Select all
<?php
$query = "SELECT DATE_FORMAT(dateField, '%m-%d-%Y')";
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Need help with display date
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?
$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?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Need help with display date
Code: Select all
<?php
...DATE_FORMAT(wp_ebyz_card_usage.date, '%m-%d-%Y')...
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering