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
https://forums.phpfreaks.com/topic/157241-solved-mysql-date-format/
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++;
				}
			?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.