0

Can somebody tell if my below code is correct.I calculate difference between date requested and current time.But I'm getting the $timediff value in negative like this: -28200

    $dateRequest =  "2015-08-21 15:16:02";
    date_default_timezone_set("Asia/Kuala_Lumpur");
    echo "now ".$now=date('Y-m-d, g:i A',time());
    $timezone_offset = +8;
    echo "then ".$then=date('Y-m-d, g:i A', strtotime($dateRequest)+$timezone_offset*60*60);

    echo "<<".$timediff = strtotime($now) - strtotime($then);// in seconds
     if($timediff > 120)// 120  is 2 mins
    {
        echo "Expired Link";
    }
112233
  • 2,406
  • 3
  • 38
  • 88
  • possible duplicate of [How to calculate the difference between two dates using PHP?](http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – Qirel Aug 21 '15 at 07:31
  • @Qirel, I think it's not...coz mine has time in hour min and sec also. SO the difference need to be done for date and time and not date alone. – 112233 Aug 21 '15 at 08:08

1 Answers1

1

In your example

$then date is always in the future by 8 hours (8*60*60) = 28800

It's just basic maths

$now - ($then + 28800) = -28800
nathanmac
  • 455
  • 1
  • 6
  • 14