The following Mysql SELECT-part of Timestampdiff
$result_all = mysql_query("SELECT *, TIMESTAMPDIFF(MINUTE,aktualisiert,NOW()) AS quote_diff FROM sms WHERE gesendet ='1' AND DATE_FORMAT( aktualisiert, '%Y' ) = '2015' AND trash ='0' ORDER BY aktualisiert DESC");
seems not to work with the if else PHP Code
<?php
$qd = $row['quote_diff'];
$qdint = intval($qd);
$zahl = intval(100);
echo $qdint;
if ( $qdint > $zahl) {echo " minutes"; }
else { echo " minute"; }
var_dump($qdint); //int(91)
var_dump($zahl); //int(100)
?>
Also var_dump says, there are both integer.
But why is there no reaction of is bigger than > (or is smaller than < or is equal to ==)?
Found a working solution, without Timestampdiff:
$result_all = mysql_query("SELECT * FROM sms WHERE gesendet ='1' AND DATE_FORMAT( aktualisiert, '%Y' ) = '2015' AND trash ='0' ORDER BY aktualisiert DESC");
(because a known problem dev.mysql.com...12.7...user comment from April 9 2004
<?php $now = time();
$lastLogin = strtotime($row['aktualisiert']);
$diff = $now - $lastLogin;
$now = date('YmdHis',$now);
$diffecho = idate('i',$diff);
if($diff > 59 && $diff < 119) { // 3600 seconds is 1 hour
echo $diffecho." minute ago"; }
else { echo $diffecho." minutes ago"; }
?>
Use the PHP function i date, if you don't want a leading zero.
There is also another cool way on developphp.com: Convert MySQL Timestamp to Ago Time Format OOP Tutorial
Maybe I use this later.
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.