のような質問が2つの日付の差分を得ることについて知っていますが、すべての回答を実装していますが、コードを取得できません仕事する。2つの日付の差分を取得しようとするとエラーが発生する
私は何を達成したいことは2つの日付の違いを得ることですが、私は次のエラー/警告取得しています:
Warning: date_format() expects parameter 1 to be DateTimeInterface, object given.
私のPHPコード:
を<?php
// Include the function's library
include_once "Functions.php";
// Set default timezone_abbreviations_list
date_default_timezone_set("Europe/Athens");
// Establish connection to the database, pass the query and get the result
$connection = connect("limited"); // Read-only
$query = "SELECT `Last_Login` FROM `users`";
$result = mysqli_query($connection, $query);
// Initiate the variables
$last_login = array();
$now = date_create(date("Y-m-d h:i:s"));
if (mysqli_num_rows($result)) {
while ($data = mysqli_fetch_assoc($result)) {
array_push($last_login, date_create($data["Last_Login"]));
/* The date in the database is saved in this format : 2016-07-10 09:43:06 */
}
}
for ($i = 0; $i < count($last_login); $i++) {
$difference = date_diff($now, $last_login[$i], true) . "<br/>";
echo date_format($difference, "%d");
}
?>
どうすればこの問題を解決できますか?
'。それをdate_formatに渡すことはできません。参照:http://php.net/manual/en/dateinterval.format.php例#1を見てください。 – ymas