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" Link to comment https://forums.phpfreaks.com/topic/294940-get-time-difference-between-2-dates/ Share on other sites More sharing options...
Barand Posted February 27, 2015 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. 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! 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
Archived
This topic is now archived and is closed to further replies.