2
$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."--";

In the above code, i'm getting the present time,date and time,date value stored in the db correctly,but when i tried to find the difference between current time and time stored in the database, i cant get the difference.

When i give the time directly like strtotime('11:30:02'); the difference can be calculated but when i tried to get the time value which is stored in database, i cant!!!

Help me soon!!! I'm trying a lot....

Keerthi
  • 117
  • 1
  • 2
  • 10

1 Answers1

2

Try this you need to specifically set the timezone else by default it takes 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";
Susheel Singh
  • 3,824
  • 5
  • 31
  • 66
  • "date_default_timezone_set("Asia/Kolkata");"---> After i have added this code,i'm getting the difference.Thank you so much !! – Keerthi May 19 '14 at 05:18