Hi All I am trying to format the sql ouput reg_date into a date format current details echoed out 2013 - 03 - 08 12:12:11 I just require the date only

echo stripslashes($row['reg_date'])

$result = $mysqli->query($query) or die ($mysqli->error.__LINE__);

 if($result->num_rows > 0)
    {
      while($row = $result->fetch_assoc())
     {
  echo stripslashes($row['reg_date']) . "  " . stripslashes($row['centre_name'])."<br>";
     }
   else
   {
   echo "No results found";
   }
 mysqli_close($mysqli);

Thanks in advance
D

If it's a datetime column, you can format it with the date function.

Hi Pritaeas thanks for the reply. I have looked at the date forums and I can't see how date() wraps around the element ( echo stripslashes($row['reg_date'] )

thanks

D

You can do this;

$date_of_reg = $row['reg_date'];
echo date("l, F d, Y",strtotime($date_of_reg));

This will display your date as [eg]; Thursday, January 01, 1970.

Hope that helps

Hi Webville thanks for your reply
I am just looking for 22-05-2013 as the output

can you assist further

Thanks

David

Yes, all you have to do is;

$date_of_reg = $row['reg_date'];
echo date("d-m-Y",strtotime($date_of_reg));

That should do the trick!!

Member Avatar for diafol

You could even do this as part of your query:

"SELECT ..., DATE_FORMAT(`reg_date`, '%d-%m-%Y') AS mydate FROM ..."

So the $row['mydate'] now contains your formatted date.

diafol - thanks for sorting it

D

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.