Please i need someone who can help me Display Date from Mysql which is in format
YYYY/MM/DD to DD/MM/YYYY the code below sends data to mysql but when i`m displaying date it comes in YYYY/MM/DD.

<?php
include"config.php";

$comment=$_POST['comment'];
$news_id=$_POST['news_id'];
$name=$_POST['name'];
//$rece_user=$_POST['rece_user'];


$query="INSERT INTO newscomment (name,news_id,time,comment,date) VALUES('$name','$news_id',CURTIME(),'$comment',CURDATE())"; 
$result=mysql_query($query);
if($result){
//echo"<i><b><font color=green size=5>your comment published successfully</font></b></i>";
//echo"message sent";
include"news.php";
}else{
echo"problem in sending";
}





?>

your help please!!!!

Are you storing this in the database as a timestamp, date, or string?

One way to convert it is when you fetch the date from the table convert it to the correct format:

$split_date=explode("/", $date_var);
$date=$split_date[2] . "/" . $split_date[1] . "/" . $split_date[0];

Depending on which format you store the date as in the database there may be easier ways of doing this.

or you could select it this way

select date_format(date '%d/%m/%Y') as formatted_date from tablename;

Can you please use my data to display it,it will help me alot coz its like i didn`t understand ur idea.
i stored the date in mysql as date.

Please i need someone who can help me Display Date from Mysql which is in format
YYYY/MM/DD to DD/MM/YYYY the code below sends data to mysql but when i`m displaying date it comes in YYYY/MM/DD.

I don't see where you are trying to pull the data from the database to incorporate it into. you need to start with a select sql clause and then loop through the results displaying each desired row.

the code is the one i used to display my data

<?php 
   
$cmid=$_GET['id'];
   
   $query="SELECT *FROM newscomment WHERE news_id='$cmid'";
   //$test="SELECT date_format(date '%d/%m/%Y') AS formatted_date FROM newscomment";
   //$re=mysql_query($test);
$result=mysql_query($query);
$count=mysql_num_rows($result);
?>
<?php
 echo"<b> Comments <font color=brown size=> $count</font></b></font>";
 ?>
 <?php
while($row=mysql_fetch_array($result)){
             //$cmid=$row['id']; 
           $name=$row['name'];
           $time=$row['time'];
		   $comment=$row['comment'];
           //$date=$row['date'];
		 // DATE_FORMAT(your_date, "%d-%e-%Y") 
	
?>

<center>
<table width="100%" cellspacing="0" cellpadding="0" height="" border="0" align="center" bgcolor=aliceblue>
   <tr><td valign=top><?php echo"<font color=black size=><b><i>$comment</i></b></font><br>"; echo"<font color=darkblue size=><b>$name Date sent:$date at $time</b></font>"; ?></td></tr>
   
   </table>

</center>

<?php
		  }
		   
   ?>
<?php 
   
$cmid=$_GET['id'];
   
   $query="SELECT date_format(date '%d/%m/%Y') AS formatted_date, * FROM newscomment WHERE news_id='$cmid'";
   //$test="SELECT date_format(date '%d/%m/%Y') AS formatted_date FROM newscomment";
   //$re=mysql_query($test);
$result=mysql_query($query);
$count=mysql_num_rows($result);
?>
<?php
 echo"<b> Comments <font color=brown size=> $count</font></b></font>";
 ?>
 <?php
while($row=mysql_fetch_array($result)){
             //$cmid=$row['id']; 
           $name=$row['name'];
           $time=$row['time'];
		   $comment=$row['comment'];
           //$date=$row['date'];
           //$formatted_date = $row['formatted_date'];
		 // DATE_FORMAT(your_date, "%d-%e-%Y") 
	
?>

<center>
<table width="100%" cellspacing="0" cellpadding="0" height="" border="0" align="center" bgcolor=aliceblue>
   <tr><td valign=top><?php echo"<font color=black size=><b><i>$comment</i></b></font><br>"; echo"<font color=darkblue size=><b>$name Date sent:$date at $time</b></font>"; ?></td></tr>
   
   </table>

</center>

<?php
		  }
		   
   ?>

After i inserted the code as u wrote,i got the following Error.May be u forgot something in that code?Coz me i`m not familiar with it.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\web\newscomment.php on line 132
Comments 
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\web\newscomment.php on line 138

I forget if you can do "colname, *" in the column list in a select query in mysql. I know you can in postgres, sometimes I forget that mysql doesn't have as many features as postgres. You may have to list the columns that you want to include in your script in the query. Something like this

$query="SELECT date_format(date '%d/%m/%Y') AS formatted_date, name, time, comment FROM newscomment WHERE news_id='$cmid'";

and what ever other columns you want to use in your scirpt.

Yeah!!this one works))Thank you alot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.