php - Is mysql datetime not compatible with strtotime()? -
i'm passing function mysql datetime , returning nothing. mysql datetime not compatible strtotime()? assume foreach loop ending , return variable not being called, why?
function timeago($time) { $time = time() - strtotime($time); // time since moment $tokens = array ( 1 => 'second', 60 => 'minute', 3600 => 'hour', 86400 => 'day', 604800 => 'week', 2592000 => 'month', 31536000 => 'year' ); foreach ($tokens $unit => $text) { if ($time < $unit) continue; $numberofunits = floor($time / $unit); return $numberofunits.' '.$text.(($numberofunits>1)?'s':'').' ago'; } }
update code gets database, there no quotes in datetime string.
while ($row = mysqli_fetch_assoc($result)) { $commenttime = $row["time"]; $commentcomment = $row["comment"]; $commentcommenter = $row["commenter"]; }
and code echo it: echo '<h3 class="party-time">'.timeago($commenttime).'</h3>';
the problem timezone issue. manually setting date in sql server using set datetime local time, server's timezone -3 hours, causing issues.
Comments
Post a Comment