0

I want to compare if difference between current date and date from database is hours or days. I tried the following but there is notice:

Call to a member function format() on a non-object

My code is:

 $date =  new DateTime('now');
 $current =$date->format('Y-m-d h:i:s');
 $newDate = DateTime::createFromFormat("l dS F Y", $final['created_at']);
 $newDate = $newDate->format('Y-m-d h:i:s'); 
         

Whick is the correctway to do this compare?I want if difference is hours, to show howrs, if difference is days, to show only count days without hours.

Thanks in advance!

ivva
  • 2,819
  • 9
  • 31
  • 64
  • 3
    Or parhaps http://stackoverflow.com/questions/2040560/finding-the-number-of-days-between-two-dates or http://stackoverflow.com/questions/5988450/difference-between-2-dates-in-seconds or http://stackoverflow.com/questions/10427694/php-difference-in-months-between-two-dates or http://stackoverflow.com/questions/9915248/php-finding-the-difference-between-dates or http://stackoverflow.com/questions/3028491/php-weeks-between-2-dates or http://stackoverflow.com/questions/10696654/get-total-time-difference-between-two-dates-using-php – PeeHaa Oct 05 '15 at 09:03
  • 3
    or http://stackoverflow.com/questions/4502832/how-to-find-the-difference-in-days-between-two-dates – PeeHaa Oct 05 '15 at 09:03
  • I used this and it helped me -> http://stackoverflow.com/questions/3108591/calculate-number-of-hours-between-2-dates-in-php Thanks! – ivva Oct 05 '15 at 11:06

0 Answers0