0

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

4
Contributors
7
Replies
39
Views
4 Years
Discussion Span
Last Post by davidjennings
0

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

0

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

0

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

can you assist further

Thanks

David

0

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!!

1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.