View Full Version : Trying to change the date format!

05-04-2005, 04:40 PM
Sorry that I keep posting this same script!

Im just trying to make the dates of the shows be formatted as "June 10th" for example.

I have searched threads on here and found this thread...

I tried using the solution by inserting $date = date('F d, Y', strtotime($date)); and then using $date as the variable to echo. However all my dates then for some obscure reason become May 4th...

Anyone know what I'm doing wrong? My script is functional but this will make it much more prettiful :D

require ('../../dryriseconnect.php');

//select future show dates from db
$result = mysql_query('SELECT * FROM shows WHERE showdate > DATE_SUB(CURDATE(), INTERVAL 0 DAY) ORDER BY showdate ASC',$db) or die ('Unable to perform selectquery. Exit script');

//if no rows returned, then say so

if (mysql_num_rows($result) < 1){
echo 'No dates to display.';
} else {

$last_month = "";

while ($row=mysql_fetch_assoc($result))

if($last_month != date("F", strtotime($row['showdate'])))
echo '<p class="heading">' . date("F", strtotime($row['showdate'])) . '<p>';

echo '<p class="main">' . $row['showdate'] . ' - ' . $row['venue'] . ', ' . $row['location'] . "\n" . '</span><br>' . "\n" .
'<span class="main">' . $row['showinfo'] . '</span>' . "\n";

$last_month = date("F", strtotime($row['showdate']));


SeeIT Solutions
05-04-2005, 04:49 PM
How are your dates stored in you database?

Did you add all of those dates you tested on the 4th May? It sounds like you added them through phpmyadmin and didn't remove the NOW() function when you were adding dates, 'cos I can't see anything wrong with your code.

If you have to go through all the dates and redo them, I would recommend storing them in the database as UNIX_TIMESTAMP's and then removing all the strtotime() functions you have everywhere.

05-04-2005, 05:02 PM
I don't think it's to do with the database. The dates are in DATE format and manually inserted.

The dates are OK at the moment, just in the wrong format... heres the code working:


I just want to change them. The code I showed didnt include the alteration which made it go wrong, i had simply added one line of code

$date = date('F d, Y', strtotime($date));

and then instead of echoing $row['showdate'] i echoed $date

Then it all went horrible wrong!

SeeIT Solutions
05-04-2005, 06:07 PM
$date = date('F d, Y', strtotime($date));

That will stuff it up because... $date is being used twice in that function, use a different variable name...

Velox Letum
05-04-2005, 07:10 PM
Are you just trying to change the format of the output date? Or is something wrong with the date output its self?

Changing date format: http://us2.php.net/function.date

If not, make sure that the lines of code you added are inside the while, otherwise it will be outputting a NULL date, and date() will just output the current date.

05-05-2005, 01:39 PM
Wicked. Thats it.

I had the bit of code to reformat the date outside the WHILE and hence why it kept giving the shows the wrong date.


Velox Letum
05-05-2005, 07:44 PM
Glad to help, and the page looks good. Just be sure to change the title ;).