Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-04-2005, 03:40 PM   PM User | #1
dysfunctionGazz
Regular Coder

 
Join Date: Jul 2002
Location: Brighton
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
dysfunctionGazz is an unknown quantity at this point
Trying to change the date format!

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...
http://www.codingforums.com/showthread.php?t=57580

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



<?php
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']));

}
}
?>
dysfunctionGazz is offline   Reply With Quote
Old 05-04-2005, 03:49 PM   PM User | #2
SeeIT Solutions
Regular Coder

 
Join Date: May 2005
Posts: 563
Thanks: 0
Thanked 3 Times in 3 Posts
SeeIT Solutions is on a distinguished road
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.
SeeIT Solutions is offline   Reply With Quote
Old 05-04-2005, 04:02 PM   PM User | #3
dysfunctionGazz
Regular Coder

 
Join Date: Jul 2002
Location: Brighton
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
dysfunctionGazz is an unknown quantity at this point
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:

http://www.suicidenotesmusic.net/dryrise/shows.php

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!
dysfunctionGazz is offline   Reply With Quote
Old 05-04-2005, 05:07 PM   PM User | #4
SeeIT Solutions
Regular Coder

 
Join Date: May 2005
Posts: 563
Thanks: 0
Thanked 3 Times in 3 Posts
SeeIT Solutions is on a distinguished road
Quote:
Originally Posted by dysfunctionGazz
$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...
SeeIT Solutions is offline   Reply With Quote
Old 05-04-2005, 06:10 PM   PM User | #5
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
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.
__________________
"$question = ( to() ) ? be() : ~be();"
Velox Letum is offline   Reply With Quote
Old 05-05-2005, 12:39 PM   PM User | #6
dysfunctionGazz
Regular Coder

 
Join Date: Jul 2002
Location: Brighton
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
dysfunctionGazz is an unknown quantity at this point
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.

Thanks!
dysfunctionGazz is offline   Reply With Quote
Old 05-05-2005, 06:44 PM   PM User | #7
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
Glad to help, and the page looks good. Just be sure to change the title .
__________________
"$question = ( to() ) ? be() : ~be();"
Velox Letum is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:20 AM.


Advertisement
Log in to turn off these ads.