I am having a heck of a time trying to find the difference between two dates. I am getting a date out of a database and trying to compare it with the current date and time.
What I need is the number of hours between the two dates. If I format the date_diff as "%h%", I am only getting the subtracted hours between the hours, not the total time like between 2:00pm three days ago and 3:00pm today. With "%h" this only give me the result 1 hour.
With the code below, I am getting the error "Object of class DateInterval could not be converted to string" when trying to echo $SinceLastUpdate. I have tried all kinds of formatting of the dates and I am going nuts on this one.
Here is my current code:
//Database stuff
$SqLiteSqlStr = "SELECT Max(END_TIME) AS LAST_UPDATE FROM DATA_LOAD_LOG";
PDO_Connect("sqlite:$SqLiteDB");
$results = PDO_FetchAll($SqLiteSqlStr);
foreach ($results as $row) { $DataUpdated = $row["LAST_UPDATE"];}
//Make some kind of attempt to find out how old the data is
$TodaysDate = new DateTime("now");
$SinceLastUpdate = date_diff(new DateTime($DataUpdated), $TodaysDate );
echo "<br>TodaysDate " . date_format($TodaysDate,"Y-m-d H:i:s");
echo "<br>DataUpdated " . $DataUpdated;
echo "<br>SinceLastUpdate " . $SinceLastUpdate;
Right now, I don't care if the difference is in seconds, minutes or hours, I just need some kind of accurate number I can work with. What I am trying to do is check how old the data is. If it is more than three days old (72 hours), then I need to run my process to update the data.
Any help is going to be greatly appreciated.