0
date_default_timezone_set('America/New_York');

$search_date = '2012-12-19 13:22:00';
$right_now = date('Y-m-d H:i:s');
$search_date = new DateTime($search_date);
$right_now = new DateTime($right_now);
$interval = $search_date->diff($right_now);
echo $interval->format('%R%s seconds');

This displays how many seconds are different between the search date and right now.

I would expect it to return more than a two digit value because there is more than a 99 second difference between the two dates, so I am not sure what I am doing wrong.

Brad
  • 12,054
  • 44
  • 118
  • 187
  • 1
    For DateInteval's format, `%s` isn't the total number of seconds, but rather just the seconds part of the date difference (so it will only ever be in the range 0-59). I'd have posted this as part of an answer, but sergio already posted the correct way to get the total number of seconds. – Powerlord Dec 18 '13 at 19:40

1 Answers1

1

Alternatively, with very little change to your original code:-

date_default_timezone_set('America/New_York');

$search_date = new DateTime('2012-12-19 13:22:00');
$right_now = new DateTime();
$seconds = $right_now->getTimestamp() - $search_date->getTimestamp();
vascowhite
  • 18,120
  • 9
  • 61
  • 77