-1

I am relatively new to php. I have time saved in database as datetime with format 2014-08-09 15:56:28

I want to get all rows that have time difference between this updated time and current time by less than 60 seconds.

I have been searching and found TIMESTAMPDIFF , it seemed complex. Anyone can help with an easy approach or better code using above command?

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

2 Answers2

2

You can get time difference (in seconds) by this

$savedTime  = strtotime('2014-08-09 15:56:28');
$currentTime = strtotime(date('Y-m-d H:i:s'));
$differenceInSeconds = $currentTime - $savedTime;
echo $differenceInSeconds;

Now customize yourself.

MH2K9
  • 11,951
  • 7
  • 32
  • 49
0

if you would like to use it in the sql query :

" SELECT pk_led
                FROM led 
                WHERE TIMESTAMPDIFF(SECOND,date_led , NOW() ) < 60 "
may saghira
  • 564
  • 9
  • 16