Using PDO I want to write from DB date without time. how convert it?
This is my PHP code:
class edit {
private $db;
public function __construct() {
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function news($newsID, $title) {
$sql= $this->db->prepare("SELECT newsID, title, date FROM `news`");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
echo '<a href="update_news.php?id='.$row['newsID'].'"><u> <b>'. $row['newsID'].' </b> </u> '.'--'.' <u> <b>'. $row['title'].' </b> </u> <u> <b>'. $row['date'].' </b> </u> </a>';
echo "<br>";
}
}
}
I want to print date only (d/m/y)please help me. thanks. :)
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date
Look for the MySQL date function and use it, perhaps:
SELECT newsID, title, DATE(date) as ymd FROM `news`
Alternatively see DATE_FORMAT
You can either use date
and strtotime
as so:
echo date('d/m/y', strtotime($row['date']));
..or if you use "newer" versions of PHP (5.2.0+
) you should use DateTime:
echo new DateTime($row['date'])->format('d/m/y');
just parse it with the date functions or the string functions for php :: http://www.w3schools.com/php/php_date.asp
it will be something like : echo date('m/d/Y', $your_timestramps);