$fetch=mysql_query("select * from code where user_email='$email' order by reg_date desc limit 1");
$db=mysql_fetch_array($fetch);
print_r($db);
$db_date=$db['reg_date'];
$db_time=$db['time'];
echo "DB_Date:".$db_date."--";
echo "DB_time:".$db_time."--";
$current_date = date('Y-m-d');
echo "present date".$current_date."--";
$curent_time = date('H:i:s');
echo "current time:".$curent_time."--";
$first_time = strtotime($curent_time);
$last_time = strtotime($db_time);
$time = $first_time - $last_time;
$time_differenc= ($time/60)%60;
echo "difference".$time_difference."--";
在上面的代码中,我正在正确获取数据库中存储的当前时间,日期和时间,日期值,但是当我试图找到当前时间与数据库中存储的时间之间的时差时,我无法获得时差。
当我像strtotime('11:30:02')那样直接给时间时;可以计算出差异,但是当我尝试获取存储在数据库中的时间值时,我无法!!!
快帮我!!!我正在努力...
尝试此操作,您需要专门设置时区,否则默认情况下需要 UTC
$dbdatetime = $row['datetime'];//datetime from database: "2014-05-18 18:10:18"
date_default_timezone_set("Asia/Kolkata"); //setting default timezone based on your location
$curdatetime = date("Y-m-d H:i:s"); //current datetime
if($curdatetime > $dbdatetime){
$diff = abs(strtotime($curdatetime) - strtotime($dbdatetime));
}else{
$diff = abs(strtotime($dbdatetime) - strtotime($curdatetime));
}
echo "The difference is "$diff/60." minutes";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句