View Full Version : reformat date brought bad results
I am Abby
08-16-2010, 06:26 PM
The date in my database looks like 2010-08-18
I want to format the date to make it look like August 18, 2010
$result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() ORDER BY dt")
or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo"<p>Name: {$row['dt']}<br />".
"Decription: {$row['description']}</p>";
Can anyone tell me how I can change my code to get the correct format. After looking at the online php manual I got some real bad results...not posting the bad code or you would laugh.
I am Abby
08-17-2010, 03:12 PM
// Retrieve all the data from the "webcalendar_events" table
$result = mysql_query("SELECT * FROM webcalendar_events WHERE dt >= now() AND color='ffff00' ORDER BY dt")
or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo"<p>Name: {$row['dt']}<br />".
"Decription: {$row['description']}</p>";
}
So first I want to split the date
list($year, $month, $day) = split('[/.-]', {$row['dt']};
But I get a message that there was an unexpected "{". If I remove the pair, it doesn't like the ";".
Help!
in your specific example above:
list($year, $month, $day) = split('[/.-]', {$row['dt']});I didn't look at anything else yet, though.
I am Abby
08-17-2010, 04:01 PM
How could I mis that?
thanks.
I am Abby
08-17-2010, 04:36 PM
{
list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = date(M);
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
}
This code makes all the months the same as the first one.
So I tried changing the code to
{
list($year, $month, $day) = split('[/.-]', $row['dt']);
echo "<p><strong>{$month = date(M)} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
}
which it did not like at all.
is this
list($year, $month, $day) = split('[/.-]', $row['dt']);
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
giving you what you want, with the exception that the month is still numeric (e.g., "8" instead of "August")?
If so, add an array of all the months and use it to convert your $month:
$monthnames = array(
"1"=>"January",
"2"=>"February"
//etc
);
list($year, $month, $day) = split('[/.-]', $row['dt']);
$month = $monthnames[$month];
echo "<p><strong>{$month} {$day}, {$year}</strong><br />".
"Decription: {$row['description']}</p>";
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.