Jump to content

[SOLVED] mysql date format


frobak

Recommended Posts

Hi

Im trying to format mysql dates to uk dd/mm/yyyy in a select statement and im struggling to get it to work.

 

Heres the select statement:

 

$query="SELECT * FROM events WHERE event_date >= CURdate() ORDER BY event_date ASC";

 

ive tried this and it didnt work?

 

$query="SELECT * FROM events

WHERE DATE_FORMAT(event_date,'%d/%m/%Y') >= CURdate()

ORDER BY event_date ASC";

 

any help would be appreciated

 

cheers

Link to comment
Share on other sites

thanks but i get the following errors after changing as above:

 

Warning: mysql_result() [function.mysql-result]: DATE_FORMAT not found in MySQL result index 4 in /home/frobakco/public_html/rockinghorsenights.com/eventpage.php on line 47

 

Warning: mysql_result() [function.mysql-result]: band_name not found in MySQL result index 4 in /home/frobakco/public_html/rockinghorsenights.com/eventpage.php on line 48

 

Warning: mysql_result() [function.mysql-result]: narrative not found in MySQL result index 4 in /home/frobakco/public_html/rockinghorsenights.com/eventpage.php on line 49

 

heres the full php code:

 

				<?php
				include("includes/db_connect.inc.php");

				$query="SELECT DATE_FORMAT(event_date,'%d/%m/%Y')  FROM events WHERE event_date >= CURDATE() ORDER BY event_date";
				$result=mysql_query($query);

				$num=mysql_numrows($result);

				mysql_close();

				$i=0;
				while ($i < $num) {

				$event_date = mysql_result($result,$i,'event_date');
				$band_name = mysql_result($result,$i,'band_name');
				$narrative = mysql_result($result,$i,'narrative');

				echo "<div id='eventbox'>
						<table id='events'>
							<th colspan='2'>$event_date
							</th>
							<tr>
								<th>$band_name
								</th>
							</tr>
							<tr>
								<td id='events'>$narrative
								</td>
							</tr>
						</table>
					</div>";
				$i++;
				}
			?>

Link to comment
Share on other sites

Use column alias and add other columns.

SELECT DATE_FORMAT(event_date,'%d/%m/%Y') AS event_date_formatted, band_name, narrative  FROM events WHERE event_date >= CURDATE() ORDER BY event_date

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.