Reputation: 23
In a php-script I do a query for reading record from my sql-database. In every -record there is a datefield 'birthdate'. This datefield is a bigint typefield. The result of my script is a unix-timestamp and a empty field. What is wrong? See my code. The result:
Birthdate Birthdate
157766400 01-01-1970
410227200 01-01-1970
and so on
...
<?php
$pdo = new PDO('mysql:host=localhost;dbname=local-db;charset=utf8', 'root', '');
$sql = "SELECT birthdate FROM wp_pdb WHERE 1;
foreach ($pdo->query($sql) as $row) {
echo "<tr><td>" .
$row['birthdate'] . "</td><td>" .
date('d-m-Y',strtotime($row['birthdate'])) . "</td><td>" .
"<br /> ";
}
?>
...
Upvotes: 1
Views: 399
Reputation: 669
Have you try this?
DATE_FORMAT(FROM_UNIXTIME(`date`), '%d-%m-%Y') AS 'date'
Upvotes: 2
Reputation: 23664
No need to use strtotime - the number you're getting is already parsed that way. Just do
date('d-m-Y', $row['birthdate'])
Upvotes: 1