feddie1984 Posted April 15, 2010 Share Posted April 15, 2010 I have the below code and would like a way to display the output as dd/mm/yyyy instead of yyyy-mm-dd as it is stored in the MySQL Database. Also if I could get some help formatting dd/mm/yyyy as yyyy-mm-dd from a form input so that I can add it to the database. <?php $dbhost = ""; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $from = $_GET['from']; $to = $_GET['to']; // Escape User Input to help prevent SQL Injection $from = mysql_real_escape_string($from); $to = mysql_real_escape_string($to); //build query $query = "SELECT * FROM ajax_example1 WHERE Date_Format(ae_date, '%d/%m/%Y') between '$from' and '$to'"; //Execute query $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Date</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[ae_name]</td>"; $display_string .= "<td>$row[ae_date]</td>"; $display_string .= "</tr>"; } echo "Query: " . $query . "<br />"; $display_string .= "</table>"; echo $display_string; ?> Link to comment https://forums.phpfreaks.com/topic/198640-date-format/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Like this: echo date("d/m/Y", strtotime($row['ae_date'])); Link to comment https://forums.phpfreaks.com/topic/198640-date-format/#findComment-1042392 Share on other sites More sharing options...
feddie1984 Posted April 15, 2010 Author Share Posted April 15, 2010 I have tried that but here: // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[ae_name]</td>"; $display_string .= "<td>echo date("d/m/Y", strtotime($row['ae_date']))</td>"; $display_string .= "</tr>"; Which gives the error: Parse error: syntax error, unexpected T_STRING in /home/tburgess/public_html/socomec/Ajax_Test/ajax-example1.php on line 33 Can you help me with the correct syntax? Link to comment https://forums.phpfreaks.com/topic/198640-date-format/#findComment-1042412 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 :-\ Um... sorry, but I'm just going to let you resolve that issue. Take a look at the color highlighting of your code snippet above and you should be able to find out what's wrong. If not, read up on PHP 101. Link to comment https://forums.phpfreaks.com/topic/198640-date-format/#findComment-1042413 Share on other sites More sharing options...
feddie1984 Posted April 15, 2010 Author Share Posted April 15, 2010 All sorted, it's been a long week thanks for our help!! // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[ae_name]</td>"; $display_string .= "<td>" . date("d/m/Y", strtotime($row['ae_date'])) . "</td>"; $display_string .= "</tr>"; } Link to comment https://forums.phpfreaks.com/topic/198640-date-format/#findComment-1042417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.