vanquish12 Posted February 27, 2015 Share Posted February 27, 2015 I need to get the time difference between two dates. Here's what I have function getTodayDate(){ $today = date('Y-m-d H:i:s'); return $today; } function checkTimeDifference($previousTime){ $today = $previousTime->diff(new DateTime(getTodayDate())); $minutes = $today->days * 24 * 60; $minutes += $today->h * 60; $minutes += $today->i; return $minutes . ' minutes'; } however it's complaining about the call to diff "Call to a member function diff() on a non-object" Quote Link to comment https://forums.phpfreaks.com/topic/294940-get-time-difference-between-2-dates/ Share on other sites More sharing options...
Solution Barand Posted February 27, 2015 Solution Share Posted February 27, 2015 Are you passing $previous time as a string value to your function? Your code expects a DateTime object. Hint: $today = new DateTime(); will give the current date time without any argument. Quote Link to comment https://forums.phpfreaks.com/topic/294940-get-time-difference-between-2-dates/#findComment-1506940 Share on other sites More sharing options...
vanquish12 Posted February 27, 2015 Author Share Posted February 27, 2015 thanks, that was it! Quote Link to comment https://forums.phpfreaks.com/topic/294940-get-time-difference-between-2-dates/#findComment-1506941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.